class IOP::ZlibDecompressor
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
@since 0.1
Public Class Methods
new(*args)
click to toggle source
Creates class instance.
@param args [Array] arguments passed to Zlib::Inflate
constructor
# File lib/iop/zlib.rb, line 81 def initialize(*args) @args = args end
Public Instance Methods
process(data = nil)
click to toggle source
Calls superclass method
IOP::Sink#process
# 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!()
click to toggle source
Calls superclass method
IOP::Sink#process!
# File lib/iop/zlib.rb, line 94 def process! @inflate = Zlib::Inflate.new(*@args) begin super ensure @inflate.close end end