Class: ZipKit::Streamer::StoredWriter
- Inherits:
-
Object
- Object
- ZipKit::Streamer::StoredWriter
- Includes:
- WriteShovel
- Defined in:
- lib/zip_kit/streamer/stored_writer.rb
Overview
Sends writes to the given io
, and also registers all the data passing
through it in a CRC32 checksum calculator. Is made to be completely
interchangeable with the DeflatedWriter in terms of interface.
Constant Summary collapse
- CRC32_BUFFER_SIZE =
The amount of bytes we will buffer before computing the intermediate CRC32 checksums. Benchmarks show that the optimum is 64KB (see `bench/buffered_crc32_bench.rb), if that is exceeded Zlib is going to perform internal CRC combine calls which will make the speed go down again.
64 * 1024
Instance Method Summary collapse
-
#<<(data) ⇒ Object
Writes the given data to the contained IO object.
-
#finish ⇒ Hash
Returns the amount of data written and the CRC32 checksum.
-
#initialize(io) ⇒ StoredWriter
constructor
A new instance of StoredWriter.
Methods included from WriteShovel
Constructor Details
#initialize(io) ⇒ StoredWriter
Returns a new instance of StoredWriter.
15 16 17 18 19 |
# File 'lib/zip_kit/streamer/stored_writer.rb', line 15 def initialize(io) @io = ZipKit::WriteAndTell.new(io) @crc_compute = ZipKit::StreamCRC32.new @crc = ZipKit::WriteBuffer.new(@crc_compute, CRC32_BUFFER_SIZE) end |
Instance Method Details
#<<(data) ⇒ Object
Writes the given data to the contained IO object.
25 26 27 28 29 |
# File 'lib/zip_kit/streamer/stored_writer.rb', line 25 def <<(data) @io << data @crc << data self end |
#finish ⇒ Hash
Returns the amount of data written and the CRC32 checksum. The return value can be directly used as the argument to ZipKit::Streamer#update_last_entry_and_write_data_descriptor
35 36 37 38 |
# File 'lib/zip_kit/streamer/stored_writer.rb', line 35 def finish @crc.flush {crc32: @crc_compute.to_i, compressed_size: @io.tell, uncompressed_size: @io.tell} end |