class Zip::ZipEntry

Constants

CDIR_ENTRY_STATIC_HEADER_LENGTH
CENTRAL_DIRECTORY_ENTRY_SIGNATURE
DEFLATED
FSTYPES
FSTYPE_ACORN
FSTYPE_AMIGA
FSTYPE_ATARI
FSTYPE_ATHEOS
FSTYPE_BEOS
FSTYPE_CPM
FSTYPE_FAT
FSTYPE_HPFS
FSTYPE_MAC
FSTYPE_MAC_OSX
FSTYPE_MVS
FSTYPE_NTFS
FSTYPE_QDOS
FSTYPE_TANDEM
FSTYPE_THEOS
FSTYPE_TOPS20
FSTYPE_UNIX
FSTYPE_VFAT
FSTYPE_VMS
FSTYPE_VM_CMS
FSTYPE_Z_SYSTEM
LOCAL_ENTRY_SIGNATURE
LOCAL_ENTRY_STATIC_HEADER_LENGTH
LOCAL_ENTRY_TRAILING_DESCRIPTOR_LENGTH
STORED
VERSION_NEEDED_TO_EXTRACT

Attributes

comment[RW]
compressed_size[RW]
compression_method[RW]
crc[RW]
dirty[RW]
externalFileAttributes[RW]
extra[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]

Public Class Methods

new(zipfile = "", name = "", comment = "", extra = "", compressed_size = 0, crc = 0, compression_method = ZipEntry::DEFLATED, size = 0, time = DOSTime.now) click to toggle source
# File lib/zip/zip_entry.rb, line 61
    def initialize(zipfile = "", name = "", comment = "", extra = "",
                   compressed_size = 0, crc = 0, 
                   compression_method = ZipEntry::DEFLATED, size = 0,
                   time  = DOSTime.now)
      super()
      if name.start_with?("/")
        raise ZipEntryNameError, "Illegal ZipEntry name '#{name}', name must not start with /"
      end
      @localHeaderOffset = 0
      @local_header_size = 0
      @internalFileAttributes = 1
      @externalFileAttributes = 0
      @header_signature = CENTRAL_DIRECTORY_ENTRY_SIGNATURE
      @versionNeededToExtract = VERSION_NEEDED_TO_EXTRACT
      @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
      @gp_flags = 0

      @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

      @dirty = false
    end

Protected Class Methods

read_local_entry(io) click to toggle source
# File lib/zip/zip_entry.rb, line 219
def read_local_entry(io)
  entry = new(io.path)
  entry.read_local_entry(io)
  entry
rescue ZipError
  nil
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/zip/zip_entry.rb, line 475
def <=> (other)
  return to_s <=> other.to_s
end
==(other) click to toggle source
# File lib/zip/zip_entry.rb, line 462
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
create_directory(destPath) { |self, destPath| ... } click to toggle source
# File lib/zip/zip_entry.rb, line 588
def create_directory(destPath)
  if ::File.directory?(destPath)
    return
  elsif ::File.exists?(destPath)
    if block_given? && yield(self, destPath)
      FileUtils::rm_f destPath
    else
      raise ZipDestinationFileExistsError,
        "Cannot create directory '#{destPath}'. "+
        "A file already exists with that name"
    end
  end
  Dir.mkdir destPath
  set_extra_attributes_on_path(destPath)
end
directory?() click to toggle source

Returns true if the entry is a directory.

# File lib/zip/zip_entry.rb, line 140
def directory?
  raise ZipInternalError, "current filetype is unknown: #{self.inspect}" unless @ftype
  @ftype == :directory
end
Also aliased as: is_directory
extract(destPath = @name, &onExistsProc) click to toggle source

Extracts entry to file destPath (defaults to @name).

# File lib/zip/zip_entry.rb, line 180
def extract(destPath = @name, &onExistsProc)
  onExistsProc ||= proc { Zip.options[:on_exists_proc] }

  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
file?() click to toggle source

Returns true if the entry is a file.

# File lib/zip/zip_entry.rb, line 147
def file?
  raise ZipInternalError, "current filetype is unknown: #{self.inspect}" unless @ftype
  @ftype == :file
end
get_input_stream() { |instance| ... } click to toggle source

Returns an IO like object for the given ZipEntry. Warning: may behave weird with symlinks.

# File lib/zip/zip_entry.rb, line 481
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
get_raw_input_stream(&aProc) click to toggle source
# File lib/zip/zip_entry.rb, line 559
def get_raw_input_stream(&aProc)
  ::File.open(@zipfile, "rb", &aProc)
end
is_directory() click to toggle source
Alias for: directory?
mtime() click to toggle source
Alias for: time
parent_as_string() click to toggle source
# File lib/zip/zip_entry.rb, line 553
def parent_as_string
  entry_name = name.chomp("/")
  slash_index = entry_name.rindex("/")
  slash_index ? entry_name.slice(0, slash_index+1) : nil
end
set_time(binaryDosDate, binaryDosTime) click to toggle source
# File lib/zip/zip_entry.rb, line 565
def set_time(binaryDosDate, binaryDosTime)
  @time = DOSTime.parse_binary_dos_format(binaryDosDate, binaryDosTime)
rescue ArgumentError
  puts "Invalid date/time in zip entry"
end
time() click to toggle source
# File lib/zip/zip_entry.rb, line 120
def time
  if @extra["UniversalTime"]
    @extra["UniversalTime"].mtime
  else
    # Standard time field in central directory has local time
    # under archive creator. Then, we can't get timezone.
    @time
  end
end
Also aliased as: mtime
time=(aTime) click to toggle source
# File lib/zip/zip_entry.rb, line 131
def time=(aTime)
  unless @extra.member?("UniversalTime")
    @extra.create("UniversalTime")
  end
  @extra["UniversalTime"].mtime = aTime
  @time = aTime
end
to_s() click to toggle source
# File lib/zip/zip_entry.rb, line 196
def to_s
  @name
end
write_file(destPath, continueOnExistsProc = proc { Zip.options[:continue_on_exists_proc] }) { |self, destPath| ... } click to toggle source
# File lib/zip/zip_entry.rb, line 571
def write_file(destPath, continueOnExistsProc = proc { Zip.options[:continue_on_exists_proc] })
  if ::File.exists?(destPath) && ! yield(self, destPath)
    raise ZipDestinationFileExistsError,
      "Destination '#{destPath}' already exists"
  end
  ::File.open(destPath, "wb") do |os|
    get_input_stream do |is|
      set_extra_attributes_on_path(destPath)

      buf = ''
      while buf = is.sysread(Decompressor::CHUNK_SIZE, buf)
        os << buf
      end
    end
  end
end