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.



42
43
44
45
46
47
48
49
50
51
# File 'lib/xlsxtream/io/rubyzip.rb', line 42

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.



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

def crc
  @crc
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

Instance Method Details

#<<(data) ⇒ Object



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

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

#finishObject



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

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