Class: Zip::Deflater

Inherits:
Compressor show all
Defined in:
lib/zip/zip.rb

Overview

:nodoc:all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outputStream, level = Zlib::DEFAULT_COMPRESSION) ⇒ Deflater

Returns a new instance of Deflater.



741
742
743
744
745
746
747
# File 'lib/zip/zip.rb', line 741

def initialize(outputStream, level = Zlib::DEFAULT_COMPRESSION)
  super()
  @outputStream = outputStream
  @zlibDeflater = Zlib::Deflate.new(level, -Zlib::MAX_WBITS)
  @size = 0
  @crc = Zlib::crc32
end

Instance Attribute Details

#crcObject (readonly)

Returns the value of attribute crc.



762
763
764
# File 'lib/zip/zip.rb', line 762

def crc
  @crc
end

#sizeObject (readonly)

Returns the value of attribute size.



762
763
764
# File 'lib/zip/zip.rb', line 762

def size
  @size
end

Instance Method Details

#<<(data) ⇒ Object



749
750
751
752
753
754
# File 'lib/zip/zip.rb', line 749

def << (data)
  val = data.to_s
  @crc = Zlib::crc32(val, @crc)
  @size += val.size
  @outputStream << @zlibDeflater.deflate(data)
end

#finishObject



756
757
758
759
760
# File 'lib/zip/zip.rb', line 756

def finish
  until @zlibDeflater.finished?
	@outputStream << @zlibDeflater.finish
  end
end