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.



1075
1076
1077
1078
1079
1080
1081
# File 'lib/zip/zip.rb', line 1075

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.



1096
1097
1098
# File 'lib/zip/zip.rb', line 1096

def crc
  @crc
end

#sizeObject (readonly)

Returns the value of attribute size.



1096
1097
1098
# File 'lib/zip/zip.rb', line 1096

def size
  @size
end

Instance Method Details

#<<(data) ⇒ Object



1083
1084
1085
1086
1087
1088
# File 'lib/zip/zip.rb', line 1083

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

#finishObject



1090
1091
1092
1093
1094
# File 'lib/zip/zip.rb', line 1090

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