Class: Xlsxtream::IO::RubyZip::StreamingDeflater
- Inherits:
-
Zip::Compressor
- Object
- Zip::Compressor
- Xlsxtream::IO::RubyZip::StreamingDeflater
- Defined in:
- lib/xlsxtream/io/rubyzip.rb
Overview
RubyZip’s Deflater buffers to a StringIO until finish is called. This StreamingDeflater writes out chunks during compression.
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) ⇒ StreamingDeflater
constructor
A new instance of StreamingDeflater.
Constructor Details
#initialize(output_stream, level = Zip.default_compression, encrypter = NullEncrypter.new) ⇒ StreamingDeflater
Returns a new instance of StreamingDeflater.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/xlsxtream/io/rubyzip.rb', line 41 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 unless encrypter.is_a? ::Zip::NullEncrypter raise ::Zip::Error, 'StreamingDeflater does not support encryption' end end |
Instance Attribute Details
#crc ⇒ Object (readonly)
Returns the value of attribute crc.
63 64 65 |
# File 'lib/xlsxtream/io/rubyzip.rb', line 63 def crc @crc end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
63 64 65 |
# File 'lib/xlsxtream/io/rubyzip.rb', line 63 def size @size end |
Instance Method Details
#<<(data) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/xlsxtream/io/rubyzip.rb', line 52 def <<(data) val = data.to_s @crc = Zlib.crc32(val, @crc) @size += val.bytesize @output_stream << @zlib_deflater.deflate(data) end |
#finish ⇒ Object
59 60 61 |
# File 'lib/xlsxtream/io/rubyzip.rb', line 59 def finish @output_stream << @zlib_deflater.finish until @zlib_deflater.finished? end |