Class: ZipKit::Streamer::Writable

Inherits:
Object
  • Object
show all
Includes:
WriteShovel
Defined in:
lib/zip_kit/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)

Direct Known Subclasses

Heuristic

Instance Method Summary collapse

Methods included from WriteShovel

#write

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



13
14
15
16
17
# File 'lib/zip_kit/streamer/writable.rb', line 13

def initialize(streamer, writer)
  @streamer = streamer
  @writer = writer
  @closed = false
end

Instance Method Details

#<<(d) ⇒ self

Writes the given data to the output stream

Parameters:

  • d (String)

    the binary string to write (part of the uncompressed file)

Returns:

  • (self)


23
24
25
26
27
# File 'lib/zip_kit/streamer/writable.rb', line 23

def <<(d)
  raise "Trying to write to a closed Writable" if @closed
  @writer << d
  self
end

#closeObject

Flushes the writer and recovers the CRC32/size values. It then calls update_last_entry_and_write_data_descriptor on the given Streamer.



31
32
33
34
35
# File 'lib/zip_kit/streamer/writable.rb', line 31

def close
  return if @closed
  @streamer.update_last_entry_and_write_data_descriptor(**@writer.finish)
  @closed = true
end