Class: ZipTricks::WriteAndTell

Inherits:
Object
  • Object
show all
Defined in:
lib/zip_tricks/write_and_tell.rb

Overview

A tiny wrapper over any object that supports :<<. Adds :tell and :advance_position_by.

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ WriteAndTell

Returns a new instance of WriteAndTell.



6
7
8
9
# File 'lib/zip_tricks/write_and_tell.rb', line 6

def initialize(io)
  @io = io
  @pos = 0
end

Instance Method Details

#<<(bytes) ⇒ Object



11
12
13
14
15
16
# File 'lib/zip_tricks/write_and_tell.rb', line 11

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

#advance_position_by(num_bytes) ⇒ Object



18
19
20
# File 'lib/zip_tricks/write_and_tell.rb', line 18

def advance_position_by(num_bytes)
  @pos += num_bytes
end

#tellObject



22
23
24
# File 'lib/zip_tricks/write_and_tell.rb', line 22

def tell
  @pos
end