Class: Zippo::Filter::Compressor
- Inherits:
-
Object
- Object
- Zippo::Filter::Compressor
- Includes:
- Base
- Defined in:
- lib/zippo/filter/compressor.rb
Overview
A compressor is responsible for writing (and likely compressing) data into a zip file.
Subclasse should include a METHOD constant to indicate which zip compression method they handle. The actual compression should be implemented in the filter and tail_filter methods.
Direct Known Subclasses
Constant Summary
Constants included from Base
Instance Method Summary collapse
- #compress_to(io) ⇒ Object
-
#initialize(io) ⇒ Compressor
constructor
A new instance of Compressor.
- #read(count = nil, buf = nil) ⇒ Object
Methods included from Base
Constructor Details
#initialize(io) ⇒ Compressor
Returns a new instance of Compressor.
20 21 22 |
# File 'lib/zippo/filter/compressor.rb', line 20 def initialize(io) @io = io end |
Instance Method Details
#compress_to(io) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/zippo/filter/compressor.rb', line 28 def compress_to(io) data_size = 0 compressed_size = 0 crc32 = 0 buf = "" while read BLOCK_SIZE, buf data_size += buf.bytesize compressed_size += io.write filter(buf) crc32 = Zlib.crc32(buf, crc32) end compressed_size += io.write tail_filter [compressed_size, data_size, crc32] end |
#read(count = nil, buf = nil) ⇒ Object
24 25 26 |
# File 'lib/zippo/filter/compressor.rb', line 24 def read(count = nil, buf = nil) @io.read count, buf end |