Sha256: ce192d367fe5aa47a6c56c75627b9c6ec3dcf613c7a64ec5faad5bb19d8d0c17

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

# 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](https://youtu.be/1BVFlvRPZVM?t=2403)
# 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.
module ZipKit::WriteShovel
  # Writes the given data to the output stream. Allows the object to be used as
  # a target for `IO.copy_stream(from, to)`
  #
  # @param bytes[String] the binary string to write (part of the uncompressed file)
  # @return [Fixnum] the number of bytes written (will always be the bytesize of `bytes`)
  def write(bytes)
    self << bytes
    bytes.bytesize
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zip_kit-6.3.0 lib/zip_kit/write_shovel.rb
zip_kit-6.2.2 lib/zip_kit/write_shovel.rb
zip_kit-6.2.1 lib/zip_kit/write_shovel.rb