Class: Zip::Entry

Inherits:
Object show all
Defined in:
lib/buildr/packaging/zip.rb

Instance Method Summary collapse

Instance Method Details

#contain?(*patterns) ⇒ Boolean

:call-seq:

contain(patterns*) => boolean

Returns true if this ZIP file entry matches against all the arguments. An argument may be a string or regular expression.

Returns:

  • (Boolean)


79
80
81
82
83
# File 'lib/buildr/packaging/zip.rb', line 79

def contain?(*patterns)
  content = File.open(zipfile) { |zip| zip.read(@name) }
  patterns.map { |pattern| Regexp === pattern ? pattern : Regexp.new(Regexp.escape(pattern.to_s)) }.
    all? { |pattern| content =~ pattern }
end

#empty?Boolean

:call-seq:

empty?() => boolean

Returns true if this entry is empty.

Returns:

  • (Boolean)


70
71
72
# File 'lib/buildr/packaging/zip.rb', line 70

def empty?()
  File.open(zipfile) { |zip| zip.read(@name) }.empty?
end

#exist?Boolean

:call-seq:

exist() => boolean

Returns true if this entry exists.

Returns:

  • (Boolean)


62
63
64
# File 'lib/buildr/packaging/zip.rb', line 62

def exist?()
  File.open(zipfile) { |zip| zip.exist?(@name) }
end

#write_c_dir_entry(io) ⇒ Object

Override write_c_dir_entry to fix comments being set to a fixnum instead of string



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/buildr/packaging/zip.rb', line 86

def write_c_dir_entry(io) #:nodoc:all
  case @fstype
    when FSTYPE_UNIX
      ft = nil
      case @ftype
        when :file
          ft = 010
          @unix_perms ||= 0644
        when :directory
          ft = 004
          @unix_perms ||= 0755
        when :symlink
          ft = 012
          @unix_perms ||= 0755
        else
          raise ZipInternalError, "unknown file type #{self.inspect}"
      end

      @external_file_attributes = (ft << 12 | (@unix_perms & 07777)) << 16
  end

  io <<
    [0x02014b50,
     @version,                  # version of encoding software
     @fstype,                   # filesystem type
     10,                        # @versionNeededToExtract
     0,                         # @gp_flags
     @compression_method,
     @time.to_binary_dos_time,  # @lastModTime
     @time.to_binary_dos_date,  # @lastModDate
     @crc,
     @compressed_size,
     @size,
     @name ? @name.length : 0,
     @extra ? @extra.c_dir_size : 0,
     @comment ? comment.to_s.length : 0,
     0,                         # disk number start
     @internal_file_attributes,   # file type (binary=0, text=1)
     @external_file_attributes,   # native filesystem attributes
     @local_header_offset,
     @name,
     @extra,
     @comment
  ].pack('VCCvvvvvVVVvvvvvVV')

  io << @name
  io << (@extra ? @extra.to_c_dir_bin : "")
  io << @comment
end