Module: ZipKit::WriteShovel

Overview

A lot of objects in ZipKit accept bytes that may be sent to the << operator (the "shovel" operator). This is in the tradition of late Jim Weirich and his Builder gem. In this presentation he justifies this design very eloquently. In ZipKit we follow this example. However, there is a number of methods in Ruby - including the standard library - which expect your object to implement the write method instead. Since the write method can be expressed in terms of the << method, why not allow all ZipKit "IO-ish" things to also respond to write? This is what this module does. Jim would be proud. We miss you, Jim.

Instance Method Summary collapse

Instance Method Details

#write(bytes) ⇒ Integer

Writes the given data to the output stream. Allows the object to be used as a target for IO.copy_stream(from, to)

Parameters:

  • bytes (String)

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

Returns:

  • (Integer)

    the number of bytes written (will always be the bytesize of bytes)



18
19
20
21
# File 'lib/zip_kit/write_shovel.rb', line 18

def write(bytes)
  self << bytes
  bytes.bytesize
end