Class | Zip::ZipEntry |
In: |
lib/zip/zip.rb
|
Parent: | Object |
STORED | = | 0 |
DEFLATED | = | 8 |
FSTYPE_FAT | = | 0 |
FSTYPE_AMIGA | = | 1 |
FSTYPE_VMS | = | 2 |
FSTYPE_UNIX | = | 3 |
FSTYPE_VM_CMS | = | 4 |
FSTYPE_ATARI | = | 5 |
FSTYPE_HPFS | = | 6 |
FSTYPE_MAC | = | 7 |
FSTYPE_Z_SYSTEM | = | 8 |
FSTYPE_CPM | = | 9 |
FSTYPE_TOPS20 | = | 10 |
FSTYPE_NTFS | = | 11 |
FSTYPE_QDOS | = | 12 |
FSTYPE_ACORN | = | 13 |
FSTYPE_VFAT | = | 14 |
FSTYPE_MVS | = | 15 |
FSTYPE_BEOS | = | 16 |
FSTYPE_TANDEM | = | 17 |
FSTYPE_THEOS | = | 18 |
FSTYPE_MAC_OSX | = | 19 |
FSTYPE_ATHEOS | = | 30 |
FSTYPES | = | { FSTYPE_FAT => 'FAT'.freeze, FSTYPE_AMIGA => 'Amiga'.freeze, FSTYPE_VMS => 'VMS (Vax or Alpha AXP)'.freeze, FSTYPE_UNIX => 'Unix'.freeze, FSTYPE_VM_CMS => 'VM/CMS'.freeze, FSTYPE_ATARI => 'Atari ST'.freeze, FSTYPE_HPFS => 'OS/2 or NT HPFS'.freeze, FSTYPE_MAC => 'Macintosh'.freeze, FSTYPE_Z_SYSTEM => 'Z-System'.freeze, FSTYPE_CPM => 'CP/M'.freeze, FSTYPE_TOPS20 => 'TOPS-20'.freeze, FSTYPE_NTFS => 'NTFS'.freeze, FSTYPE_QDOS => 'SMS/QDOS'.freeze, FSTYPE_ACORN => 'Acorn RISC OS'.freeze, FSTYPE_VFAT => 'Win32 VFAT'.freeze, FSTYPE_MVS => 'MVS'.freeze, FSTYPE_BEOS => 'BeOS'.freeze, FSTYPE_TANDEM => 'Tandem NSK'.freeze, FSTYPE_THEOS => 'Theos'.freeze, FSTYPE_MAC_OSX => 'Mac OS/X (Darwin)'.freeze, FSTYPE_ATHEOS => 'AtheOS'.freeze, }.freeze |
LOCAL_ENTRY_SIGNATURE | = | 0x04034b50 |
LOCAL_ENTRY_STATIC_HEADER_LENGTH | = | 30 |
LOCAL_ENTRY_TRAILING_DESCRIPTOR_LENGTH | = | 4+4+4 |
VERSION_NEEDED_TO_EXTRACT | = | 10 |
CENTRAL_DIRECTORY_ENTRY_SIGNATURE | = | 0x02014b50 |
CDIR_ENTRY_STATIC_HEADER_LENGTH | = | 46 |
comment | [RW] | |
compressed_size | [RW] | |
compression_method | [RW] | |
crc | [RW] | |
externalFileAttributes | [RW] | |
extra | [RW] | |
follow_symlinks | [RW] | |
fstype | [RW] | |
gp_flags | [RW] | |
header_signature | [RW] | |
localHeaderOffset | [RW] | |
name | [RW] | |
restore_ownership | [RW] | |
restore_permissions | [RW] | |
restore_times | [RW] | |
size | [RW] | |
unix_gid | [RW] | |
unix_perms | [RW] | |
unix_uid | [RW] | |
zipfile | [RW] |
# File lib/zip/zip.rb, line 368 def initialize(zipfile = "", name = "", comment = "", extra = "", compressed_size = 0, crc = 0, compression_method = ZipEntry::DEFLATED, size = 0, time = Time.now) super() if name.starts_with("/") raise ZipEntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /" end @localHeaderOffset = 0 @local_header_size = 0 @internalFileAttributes = 1 @externalFileAttributes = 0 @version = 52 # this library's version @ftype = nil # unspecified or unknown @filepath = nil if Zip::RUNNING_ON_WINDOWS @fstype = FSTYPE_FAT else @fstype = FSTYPE_UNIX end @zipfile = zipfile @comment = comment @compressed_size = compressed_size @crc = crc @extra = extra @compression_method = compression_method @name = name @size = size @time = time @follow_symlinks = false @restore_times = true @restore_permissions = false @restore_ownership = false # BUG: need an extra field to support uid/gid's @unix_uid = nil @unix_gid = nil @unix_perms = nil # @posix_acl = nil # @ntfs_acl = nil if name_is_directory? @ftype = :directory else @ftype = :file end unless ZipExtraField === @extra @extra = ZipExtraField.new(@extra.to_s) end end
# File lib/zip/zip.rb, line 559 def ZipEntry.read_local_entry(io) entry = new(io.path) entry.read_local_entry(io) return entry rescue ZipError return nil end
# File lib/zip/zip.rb, line 746 def == (other) return false unless other.class == self.class # Compares contents of local entry and exposed fields (@compression_method == other.compression_method && @crc == other.crc && @compressed_size == other.compressed_size && @size == other.size && @name == other.name && @extra == other.extra && @filepath == other.filepath && self.time.dos_equals(other.time)) end
Returns the name in the encoding specified by enc
# File lib/zip/zip.rb, line 364 def comment_in(enc) Iconv.conv(enc, name_encoding, @name) end
Returns true if the entry is a directory.
# File lib/zip/zip.rb, line 442 def directory? raise ZipInternalError, "current filetype is unknown: #{self.inspect}" unless @ftype @ftype == :directory end
Extracts entry to file destPath (defaults to @name).
# File lib/zip/zip.rb, line 482 def extract(destPath = @name, &onExistsProc) onExistsProc ||= proc { false } if directory? create_directory(destPath, &onExistsProc) elsif file? write_file(destPath, &onExistsProc) elsif symlink? create_symlink(destPath, &onExistsProc) else raise RuntimeError, "unknown file type #{self.inspect}" end self end
Returns true if the entry is a file.
# File lib/zip/zip.rb, line 449 def file? raise ZipInternalError, "current filetype is unknown: #{self.inspect}" unless @ftype @ftype == :file end
Returns an IO like object for the given ZipEntry. Warning: may behave weird with symlinks.
# File lib/zip/zip.rb, line 765 def get_input_stream(&aProc) if @ftype == :directory return yield(NullInputStream.instance) if block_given? return NullInputStream.instance elsif @filepath case @ftype when :file return File.open(@filepath, "rb", &aProc) when :symlink linkpath = File::readlink(@filepath) stringio = StringIO.new(linkpath) return yield(stringio) if block_given? return stringio else raise "unknown @ftype #{@ftype}" end else zis = ZipInputStream.new(@zipfile, localHeaderOffset) zis.get_next_entry if block_given? begin return yield(zis) ensure zis.close end else return zis end end end
# File lib/zip/zip.rb, line 844 def get_raw_input_stream(&aProc) File.open(@zipfile, "rb", &aProc) end
Returns the character encoding used for name and comment
# File lib/zip/zip.rb, line 354 def name_encoding (@gp_flags & 0b100000000000) != 0 ? "utf8" : "CP437//" end
Returns the name in the encoding specified by enc
# File lib/zip/zip.rb, line 359 def name_in(enc) Iconv.conv(enc, name_encoding, @name) end
# File lib/zip/zip.rb, line 838 def parent_as_string entry_name = name.chomp("/") slash_index = entry_name.rindex("/") slash_index ? entry_name.slice(0, slash_index+1) : nil end
Returns true if the entry is a symlink.
# File lib/zip/zip.rb, line 455 def symlink? raise ZipInternalError, "current filetype is unknown: #{self.inspect}" unless @ftype @ftype == :symlink end
# File lib/zip/zip.rb, line 422 def time if @extra["UniversalTime"] @extra["UniversalTime"].mtime else # Atandard time field in central directory has local time # under archive creator. Then, we can't get timezone. @time end end