Class: Zip::Deflater
- Inherits:
-
Compressor
- Object
- Compressor
- Zip::Deflater
- Defined in:
- lib/zip/deflater.rb
Overview
:nodoc:all
Instance Attribute Summary collapse
-
#crc ⇒ Object
readonly
Returns the value of attribute crc.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #finish ⇒ Object
-
#initialize(output_stream, level = Zip.default_compression, encrypter = NullEncrypter.new) ⇒ Deflater
constructor
A new instance of Deflater.
Constructor Details
#initialize(output_stream, level = Zip.default_compression, encrypter = NullEncrypter.new) ⇒ Deflater
Returns a new instance of Deflater.
5 6 7 8 9 10 11 12 |
# File 'lib/zip/deflater.rb', line 5 def initialize(output_stream, level = Zip.default_compression, encrypter = NullEncrypter.new) super() @output_stream = output_stream @zlib_deflater = ::Zlib::Deflate.new(level, -::Zlib::MAX_WBITS) @size = 0 @crc = ::Zlib.crc32 @encrypter = encrypter end |
Instance Attribute Details
#crc ⇒ Object (readonly)
Returns the value of attribute crc.
32 33 34 |
# File 'lib/zip/deflater.rb', line 32 def crc @crc end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
32 33 34 |
# File 'lib/zip/deflater.rb', line 32 def size @size end |
Instance Method Details
#<<(data) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/zip/deflater.rb', line 14 def <<(data) val = data.to_s @crc = Zlib.crc32(val, @crc) @size += val.bytesize # When JRuby#3962 is fixed, we can remove the flushing parameter here. buffer = @zlib_deflater.deflate(data, Zip::ZLIB_FLUSHING_STRATEGY) return @output_stream if buffer.empty? @output_stream << @encrypter.encrypt(buffer) end |
#finish ⇒ Object
26 27 28 29 30 |
# File 'lib/zip/deflater.rb', line 26 def finish buffer = @zlib_deflater.finish @output_stream << @encrypter.encrypt(buffer) unless buffer.empty? @zlib_deflater.close end |