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 = ::Zlib::DEFAULT_COMPRESSION) ⇒ Deflater
constructor
A new instance of Deflater.
Constructor Details
#initialize(output_stream, level = ::Zlib::DEFAULT_COMPRESSION) ⇒ Deflater
Returns a new instance of Deflater.
4 5 6 7 8 9 10 |
# File 'lib/zip/deflater.rb', line 4 def initialize(output_stream, level = ::Zlib::DEFAULT_COMPRESSION) super() @output_stream = output_stream @zlib_deflater = ::Zlib::Deflate.new(level, -::Zlib::MAX_WBITS) @size = 0 @crc = ::Zlib.crc32 end |
Instance Attribute Details
#crc ⇒ Object (readonly)
Returns the value of attribute crc.
23 24 25 |
# File 'lib/zip/deflater.rb', line 23 def crc @crc end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
23 24 25 |
# File 'lib/zip/deflater.rb', line 23 def size @size end |
Instance Method Details
#<<(data) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/zip/deflater.rb', line 12 def << (data) val = data.to_s @crc = Zlib::crc32(val, @crc) @size += val.bytesize @output_stream << @zlib_deflater.deflate(data) end |
#finish ⇒ Object
19 20 21 |
# File 'lib/zip/deflater.rb', line 19 def finish @output_stream << @zlib_deflater.finish until @zlib_deflater.finished? end |