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



38
39
40
41
42
43
44
45
46
47
# File 'lib/xlsxtream/io/rubyzip.rb', line 38

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.



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

def crc
  @crc
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

Instance Method Details

#<<(data) ⇒ Object



49
50
51
52
53
54
# File 'lib/xlsxtream/io/rubyzip.rb', line 49

def <<(data)
  val   = data.to_s
  @crc  = Zlib.crc32(val, @crc)
  @size += val.bytesize
  @output_stream << @zlib_deflater.deflate(data)
end

#finishObject



56
57
58
# File 'lib/xlsxtream/io/rubyzip.rb', line 56

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