Class: Zippo::Filter::Uncompressor
- Inherits:
-
Object
- Object
- Zippo::Filter::Uncompressor
- Includes:
- Base
- Defined in:
- lib/zippo/filter/uncompressor.rb
Overview
An Uncompressor is responsible for reading (and likely uncompressing) member data from a Zip file.
Subclasse should include a METHOD constant to indicate which zip compression method they handle. The actual uncompression should be implemented in the filter and tail_filter methods.
Direct Known Subclasses
Constant Summary
Constants included from Base
Instance Method Summary collapse
-
#initialize(io, compressed_size) ⇒ Uncompressor
constructor
A new instance of Uncompressor.
- #read(n, buf = nil) ⇒ Object
-
#uncompress ⇒ String
The uncompressed data.
-
#uncompress_to(io) ⇒ Object
Uncompresses the data to the specified IO.
Methods included from Base
Constructor Details
#initialize(io, compressed_size) ⇒ Uncompressor
Returns a new instance of Uncompressor.
21 22 23 24 25 26 27 28 |
# File 'lib/zippo/filter/uncompressor.rb', line 21 def initialize(io, compressed_size) # XXX should probably capture the offset here # current usage assumes the IO has already been positioned at # the appropriate location @io = io @compressed_size = compressed_size @remaining = @compressed_size end |
Instance Method Details
#read(n, buf = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/zippo/filter/uncompressor.rb', line 30 def read(n, buf = nil) if @remaining >= n @remaining -= n elsif (n = @remaining) > 0 @remaining = 0 else return nil end @io.read n, buf buf.replace filter(buf) end |
#uncompress ⇒ String
Returns the uncompressed data.
53 54 55 |
# File 'lib/zippo/filter/uncompressor.rb', line 53 def uncompress uncompress_to "" end |
#uncompress_to(io) ⇒ Object
Uncompresses the data to the specified IO
46 47 48 49 50 |
# File 'lib/zippo/filter/uncompressor.rb', line 46 def uncompress_to(io) buf = "" io << buf while read BLOCK_SIZE, buf io << tail_filter end |