Class: ZipTricks::Streamer::Writable
- Inherits:
-
Object
- Object
- ZipTricks::Streamer::Writable
- Defined in:
- lib/zip_tricks/streamer/writable.rb
Overview
Gets yielded from the writing methods of the Streamer
and accepts the data being written into the ZIP for deflate
or stored modes. Can be used as a destination for IO.copy_stream
IO.copy_stream(File.open('source.bin', 'rb), writable)
Instance Method Summary collapse
-
#<<(d) ⇒ self
Writes the given data to the output stream.
-
#close ⇒ Object
Flushes the writer and recovers the CRC32/size values.
-
#initialize(streamer, writer) ⇒ Writable
constructor
Initializes a new Writable with the object it delegates the writes to.
-
#write(d) ⇒ Fixnum
Writes the given data to the output stream.
Constructor Details
#initialize(streamer, writer) ⇒ Writable
Initializes a new Writable with the object it delegates the writes to. Normally you would not need to use this method directly
11 12 13 14 15 |
# File 'lib/zip_tricks/streamer/writable.rb', line 11 def initialize(streamer, writer) @streamer = streamer @writer = writer @closed = false end |
Instance Method Details
#<<(d) ⇒ self
Writes the given data to the output stream
21 22 23 24 25 |
# File 'lib/zip_tricks/streamer/writable.rb', line 21 def <<(d) raise 'Trying to write to a closed Writable' if @closed @writer << d self end |
#close ⇒ Object
Flushes the writer and recovers the CRC32/size values. It then calls
update_last_entry_and_write_data_descriptor
on the given Streamer.
38 39 40 41 42 |
# File 'lib/zip_tricks/streamer/writable.rb', line 38 def close return if @closed @streamer.update_last_entry_and_write_data_descriptor(**@writer.finish) @closed = true end |
#write(d) ⇒ Fixnum
Writes the given data to the output stream
31 32 33 34 |
# File 'lib/zip_tricks/streamer/writable.rb', line 31 def write(d) self << d d.bytesize end |