class ZipTricks::FileReader::ZipEntry

Represents a file within the ZIP archive being read. This is different from the Entry object used in Streamer for ZIP writing, since during writing more data can be kept in memory for immediate use.

Attributes

comment[RW]

@return [String] the file comment

compressed_size[RW]

@return [Fixnum] size of compressed file data in the ZIP

crc32[RW]

@return [Fixnum] the CRC32 checksum of this file

disk_number_start[RW]

@return [Fixnum] disk number where this file starts

dos_date[RW]

@return [Fixnum] the bit-packed DOS date

dos_time[RW]

@return [Fixnum] the bit-packed DOS time

external_attrs[RW]

@return [Fixnum] external attributes of the file

filename[RW]

@return [String] the filename

gp_flags[RW]

@return [Fixnum] bit-packed general purpose flags

internal_attrs[RW]

@return [Fixnum] internal attributes of the file

local_file_header_offset[RW]

@return [Fixnum] at what offset the local file header starts

in your original IO object
made_by[RW]

@return [Fixnum] bit-packed version signature of the program that made the archive

storage_mode[RW]

@return [Fixnum] Storage mode (0 for stored, 8 for deflate)

uncompressed_size[RW]

@return [Fixnum] size of the file once uncompressed

version_needed_to_extract[RW]

@return [Fixnum] ZIP version support needed to extract this file

Public Instance Methods

compressed_data_offset() click to toggle source

@return [Fixnum] at what offset you should start reading

for the compressed data in your original IO object
# File lib/zip_tricks/file_reader.rb, line 156
def compressed_data_offset
  @compressed_data_offset || raise(LocalHeaderPending)
end
compressed_data_offset=(offset) click to toggle source

Sets the offset at which the compressed data for this file starts in the ZIP. By default, the value will be set by the Reader for you. If you use delayed reading, you need to set it by using the `get_compressed_data_offset` on the Reader:

entry.compressed_data_offset = reader.get_compressed_data_offset(io: file,
       local_file_header_offset: entry.local_header_offset)
# File lib/zip_tricks/file_reader.rb, line 178
def compressed_data_offset=(offset)
  @compressed_data_offset = offset.to_i
end
extractor_from(from_io) click to toggle source

Returns a reader for the actual compressed data of the entry.

reader = entry.extractor_from(source_file)
outfile << reader.extract(512 * 1024) until reader.eof?

@return [#extract(n_bytes), eof?] the reader for the data

# File lib/zip_tricks/file_reader.rb, line 141
def extractor_from(from_io)
  from_io.seek(compressed_data_offset, IO::SEEK_SET)
  case storage_mode
  when 8
    InflatingReader.new(from_io, compressed_size)
  when 0
    StoredReader.new(from_io, compressed_size)
  else
    raise UnsupportedFeature, 'Unsupported storage mode for reading - %<storage_mode>d' %
                              {storage_mode: storage_mode}
  end
end
known_offset?() click to toggle source

Tells whether the compressed data offset is already known for this entry @return [Boolean]

# File lib/zip_tricks/file_reader.rb, line 162
def known_offset?
  !@compressed_data_offset.nil?
end
uses_data_descriptor?() click to toggle source

Tells whether the entry uses a data descriptor (this is defined by bit 3 in the GP flags).

# File lib/zip_tricks/file_reader.rb, line 168
def uses_data_descriptor?
  (gp_flags & 0x0008) == 0x0008
end