Class: Avro::DataFile::DeflateCodec
- Inherits:
-
Object
- Object
- Avro::DataFile::DeflateCodec
- Defined in:
- lib/avro/data_file.rb
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
Instance Method Summary collapse
- #codec_name ⇒ Object
- #compress(data) ⇒ Object
- #decompress(compressed) ⇒ Object
-
#initialize(level = Zlib::DEFAULT_COMPRESSION) ⇒ DeflateCodec
constructor
A new instance of DeflateCodec.
Constructor Details
#initialize(level = Zlib::DEFAULT_COMPRESSION) ⇒ DeflateCodec
Returns a new instance of DeflateCodec.
311 312 313 |
# File 'lib/avro/data_file.rb', line 311 def initialize(level=Zlib::DEFAULT_COMPRESSION) @level = level end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
309 310 311 |
# File 'lib/avro/data_file.rb', line 309 def level @level end |
Instance Method Details
#codec_name ⇒ Object
315 |
# File 'lib/avro/data_file.rb', line 315 def codec_name; 'deflate'; end |
#compress(data) ⇒ Object
328 329 330 331 332 333 334 |
# File 'lib/avro/data_file.rb', line 328 def compress(data) zstream = Zlib::Deflate.new(level, -Zlib::MAX_WBITS) compressed = zstream.deflate(data) compressed << zstream.finish ensure zstream.close end |
#decompress(compressed) ⇒ Object
317 318 319 320 321 322 323 324 325 326 |
# File 'lib/avro/data_file.rb', line 317 def decompress(compressed) # Passing a negative number to Inflate puts it into "raw" RFC1951 mode # (without the RFC1950 header & checksum). See the docs for # inflateInit2 in https://www.zlib.net/manual.html zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS) data = zstream.inflate(compressed) data << zstream.finish ensure zstream.close end |