Class: Zip::Deflater

Inherits:
Compressor show all
Defined in:
lib/zip/deflater.rb

Overview

:nodoc:all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outputStream, level = Zlib::DEFAULT_COMPRESSION) ⇒ Deflater

Returns a new instance of Deflater.



3
4
5
6
7
8
9
# File 'lib/zip/deflater.rb', line 3

def initialize(outputStream, level = Zlib::DEFAULT_COMPRESSION)
  super()
  @outputStream = outputStream
  @zlibDeflater = Zlib::Deflate.new(level, -Zlib::MAX_WBITS)
  @size = 0
  @crc = Zlib::crc32
end

Instance Attribute Details

#crcObject (readonly)

Returns the value of attribute crc.



24
25
26
# File 'lib/zip/deflater.rb', line 24

def crc
  @crc
end

#sizeObject (readonly)

Returns the value of attribute size.



24
25
26
# File 'lib/zip/deflater.rb', line 24

def size
  @size
end

Instance Method Details

#<<(data) ⇒ Object



11
12
13
14
15
16
# File 'lib/zip/deflater.rb', line 11

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

#finishObject



18
19
20
21
22
# File 'lib/zip/deflater.rb', line 18

def finish
  until @zlibDeflater.finished?
    @outputStream << @zlibDeflater.finish
  end
end