Parent

Methods

Archive::Zip::DataDescriptor

Archive::Zip::DataDescriptor is a convenience class which bundles important information concerning the compressed data in a ZIP archive entry and allows easy comparisons between instances of itself.

Attributes

compressed_size[R]

A count of the number of bytes of compressed data associated with a set of uncompressed data.

crc32[R]

A CRC32 checksum over some set of uncompressed data.

uncompressed_size[R]

A count of the number of bytes of a set of uncompressed data.

Public Class Methods

new(crc32, compressed_size, uncompressed_size) click to toggle source

Create a new instance of this class where crc32, compressed_size, and uncompressed_size are all integers representing a CRC32 checksum of uncompressed data, the size of compressed data, and the size of uncompressed data respectively.

# File lib/archive/zip/data_descriptor.rb, line 11
def initialize(crc32, compressed_size, uncompressed_size)
  @crc32 = crc32
  @compressed_size = compressed_size
  @uncompressed_size = uncompressed_size
end

Public Instance Methods

dump(io) click to toggle source

Writes the data wrapped in this object to io which must be a writable, IO-like object providing a write method. Returns the number of bytes written.

# File lib/archive/zip/data_descriptor.rb, line 47
def dump(io)
  io.write(
    [
      crc32,
      compressed_size,
      uncompressed_size
    ].pack('VVV')
  )
end
verify(other) click to toggle source

Compares the crc32 and uncompressed_size attributes of this object with like-named attributes of other and raises Archive::Zip::Error for any mismatches.

NOTE: The compressed_size attribute is not checked because encrypted entries may have misleading compressed sizes. Checking only the CRC32 and uncompressed size of the data should be sufficient to ensure that an entry has been successfully extracted.

# File lib/archive/zip/data_descriptor.rb, line 33
def verify(other)
  unless crc32 == other.crc32 then
    raise Zip::Error,
      "CRC32 mismatch: #{crc32.to_s(16)} vs. #{other.crc32.to_s(16)}"
  end
  unless uncompressed_size == other.uncompressed_size then
    raise Zip::Error,
      "uncompressed size mismatch: #{uncompressed_size} vs. #{other.uncompressed_size}"
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.