Class: Zip::Deflater

Inherits:
Compressor show all
Defined in:
lib/zip/zip.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.



1101
1102
1103
1104
1105
1106
1107
# File 'lib/zip/zip.rb', line 1101

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.



1122
1123
1124
# File 'lib/zip/zip.rb', line 1122

def crc
  @crc
end

#sizeObject (readonly)

Returns the value of attribute size.



1122
1123
1124
# File 'lib/zip/zip.rb', line 1122

def size
  @size
end

Instance Method Details

#<<(data) ⇒ Object



1109
1110
1111
1112
1113
1114
# File 'lib/zip/zip.rb', line 1109

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

#finishObject



1116
1117
1118
1119
1120
# File 'lib/zip/zip.rb', line 1116

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