Class: Zip::ZipEntry
Instance Method Summary collapse
-
#contain?(*patterns) ⇒ Boolean
:call-seq: contain(patterns*) => boolean.
-
#empty? ⇒ Boolean
:call-seq: empty?() => boolean.
-
#exist? ⇒ Boolean
:call-seq: exist() => boolean.
-
#write_c_dir_entry(io) ⇒ Object
Override write_c_dir_entry to fix comments being set to a fixnum instead of string.
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.
68 69 70 71 72 |
# File 'lib/buildr/packaging/zip.rb', line 68 def contain?(*patterns) content = Zip::ZipFile.open(zipfile) { |zip| zip.file.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.
59 60 61 |
# File 'lib/buildr/packaging/zip.rb', line 59 def empty?() Zip::ZipFile.open(zipfile) { |zip| zip.file.read(@name) }.empty? end |
#exist? ⇒ Boolean
:call-seq:
exist() => boolean
Returns true if this entry exists.
51 52 53 |
# File 'lib/buildr/packaging/zip.rb', line 51 def exist?() Zip::ZipFile.open(zipfile) { |zip| zip.file.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
75 76 77 78 79 80 81 82 83 84 85 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 |
# File 'lib/buildr/packaging/zip.rb', line 75 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 @externalFileAttributes = (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_length : 0, @comment ? comment.to_s.length : 0, 0, # disk number start @internalFileAttributes, # file type (binary=0, text=1) @externalFileAttributes, # native filesystem attributes @localHeaderOffset, @name, @extra, @comment ].pack('VCCvvvvvVVVvvvvvVV') io << @name io << (@extra ? @extra.to_c_dir_bin : "") io << @comment end |