Sha256: df518ddb7cf2e1c8d1cb21c079aa9be0e5ae13d02409723eb8a6f5f8594996a0

Contents?: true

Size: 410 Bytes

Versions: 3

Compression:

Stored size: 410 Bytes

Contents

# frozen_string_literal: true

# A tiny wrapper over any object that supports :<<.
# Adds :tell and :advance_position_by.
class ZipTricks::WriteAndTell
  def initialize(io)
    @io = io
    @pos = 0
  end

  def <<(bytes)
    return self if bytes.nil?
    @io << bytes.b
    @pos += bytes.bytesize
    self
  end

  def advance_position_by(num_bytes)
    @pos += num_bytes
  end

  def tell
    @pos
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zip_tricks-5.6.0 lib/zip_tricks/write_and_tell.rb
zip_tricks-5.5.0 lib/zip_tricks/write_and_tell.rb
zip_tricks-5.4.0 lib/zip_tricks/write_and_tell.rb