Class: Xlsxtream::IO::RubyZip::StreamingDeflater

Inherits:
Zip::Compressor
  • Object
show all
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

Instance Method Summary collapse

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

#crcObject (readonly)

Returns the value of attribute crc.



63
64
65
# File 'lib/xlsxtream/io/rubyzip.rb', line 63

def crc
  @crc
end

#sizeObject (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

#finishObject



59
60
61
# File 'lib/xlsxtream/io/rubyzip.rb', line 59

def finish
  @output_stream << @zlib_deflater.finish until @zlib_deflater.finished?
end