Parent

Archive::Zip::Codec::Deflate::Compress

Archive::Zip::Codec::Deflate::Compress extends Zlib::ZWriter in order to specify the standard Zlib options required by ZIP archives and to provide a close method which can optionally close the delegate IO-like object. In addition a convenience method is provided for generating DataDescriptor objects based on the data which is passed through this object.

Instances of this class should only be accessed via the Archive::Zip::Codec::Deflate#compressor method.

Attributes

checksum[R]

The CRC32 checksum of the uncompressed data written using this object.

NOTE: Anything still in the internal write buffer has not been processed, so calling flush prior to examining this attribute may be necessary for an accurate computation.

crc32[R]

The CRC32 checksum of the uncompressed data written using this object.

NOTE: Anything still in the internal write buffer has not been processed, so calling flush prior to examining this attribute may be necessary for an accurate computation.

Public Class Methods

new(io, compression_level) click to toggle source

Creates a new instance of this class using io as a data sink. io must be writable and must provide a write method as IO does or errors will be raised when performing write operations. compression_level must be one of Zlib::DEFAULT_COMPRESSION, Zlib::BEST_COMPRESSION, Zlib::BEST_SPEED, or Zlib::NO_COMPRESSION and specifies the amount of compression to be applied to the data stream.

# File lib/archive/zip/codec/deflate.rb, line 42
def initialize(io, compression_level)
  super(io, compression_level, -Zlib::MAX_WBITS)
  @crc32 = 0
end
open(io, compression_level) click to toggle source

Creates a new instance of this class with the given arguments using new and then passes the instance to the given block. The close method is guaranteed to be called after the block completes.

Equivalent to new if no block is given.

# File lib/archive/zip/codec/deflate.rb, line 25
def self.open(io, compression_level)
  deflate_io = new(io, compression_level)
  return deflate_io unless block_given?

  begin
    yield(deflate_io)
  ensure
    deflate_io.close unless deflate_io.closed?
  end
end

Public Instance Methods

close(close_delegate = true) click to toggle source

Closes this object so that further write operations will fail. If close_delegate is true, the delegate object used as a data sink will also be closed using its close method.

# File lib/archive/zip/codec/deflate.rb, line 58
def close(close_delegate = true)
  super()
  delegate.close if close_delegate
end
data_descriptor() click to toggle source

Returns an instance of Archive::Zip::DataDescriptor with information regarding the data which has passed through this object to the delegate object. The close or flush methods should be called before using this method in order to ensure that any possibly buffered data is flushed to the delegate object; otherwise, the contents of the data descriptor may be inaccurate.

# File lib/archive/zip/codec/deflate.rb, line 69
def data_descriptor
  DataDescriptor.new(crc32, compressed_size, uncompressed_size)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.