Class: IOP::ZlibDecompressor
- Inherits:
-
Object
- Object
- IOP::ZlibDecompressor
- Defined in:
- lib/iop/zlib.rb
Overview
Filter class to perform data decompression with Zlib algorithm.
This class is an adapter for the standard Ruby Zlib::Inflate class.
Note that this class can not decompress .gz files - use GzipDecompressor for this purpose.
### Use case: decompress a Zlib-compressed part of a file skipping a header and compute MD5 hash sum of the uncompressed data.
require 'iop/zlib'
require 'iop/file'
require 'iop/digest'
( IOP::FileReader.new('input.dat', offset: 16) | IOP::ZlibDecompressor.new | (d = IOP::DigestComputer.new(Digest::MD5.new)) ).process!
puts d.digest.hexdigest
Direct Known Subclasses
Instance Attribute Summary
Attributes included from Sink
Attributes included from Feed
Instance Method Summary collapse
-
#initialize(*args) ⇒ ZlibDecompressor
constructor
Creates class instance.
- #process(data = nil) ⇒ Object
- #process! ⇒ Object
Methods included from Feed
Constructor Details
#initialize(*args) ⇒ ZlibDecompressor
Creates class instance.
81 82 83 |
# File 'lib/iop/zlib.rb', line 81 def initialize(*args) @args = args end |
Instance Method Details
#process(data = nil) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/iop/zlib.rb', line 85 def process(data = nil) if data.nil? super(@inflate.finish) super else super(@inflate.inflate(data)) end end |
#process! ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/iop/zlib.rb', line 94 def process! @inflate = Zlib::Inflate.new(*@args) begin super ensure @inflate.close end end |