Class: Zip::Deflater

Inherits:
Compressor show all
Defined in:
lib/hotplate/gems/rubyzip-1.1.7/lib/zip/deflater.rb

Overview

:nodoc:all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_stream, level = Zip.default_compression, encrypter = NullEncrypter.new) ⇒ Deflater

Returns a new instance of Deflater.



4
5
6
7
8
9
10
11
12
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/deflater.rb', line 4

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
  @encrypter     = encrypter
  @buffer_stream = ::StringIO.new('')
end

Instance Attribute Details

#crcObject (readonly)

Returns the value of attribute crc.



26
27
28
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/deflater.rb', line 26

def crc
  @crc
end

#sizeObject (readonly)

Returns the value of attribute size.



26
27
28
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/deflater.rb', line 26

def size
  @size
end

Instance Method Details

#<<(data) ⇒ Object



14
15
16
17
18
19
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/deflater.rb', line 14

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

#finishObject



21
22
23
24
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/deflater.rb', line 21

def finish
  @output_stream << @encrypter.encrypt(@buffer_stream.string)
  @output_stream << @encrypter.encrypt(@zlib_deflater.finish) until @zlib_deflater.finished?
end