Class: ZipTricks::WriteAndTell
- Inherits:
-
Object
- Object
- ZipTricks::WriteAndTell
- 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
- #<<(bytes) ⇒ Object
- #advance_position_by(num_bytes) ⇒ Object
-
#initialize(io) ⇒ WriteAndTell
constructor
A new instance of WriteAndTell.
- #tell ⇒ Object
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 17 |
# File 'lib/zip_tricks/write_and_tell.rb', line 11 def <<(bytes) return self if bytes.nil? binary_bytes = binary(bytes) @io << binary_bytes @pos += binary_bytes.bytesize self end |
#advance_position_by(num_bytes) ⇒ Object
19 20 21 |
# File 'lib/zip_tricks/write_and_tell.rb', line 19 def advance_position_by(num_bytes) @pos += num_bytes end |
#tell ⇒ Object
23 24 25 |
# File 'lib/zip_tricks/write_and_tell.rb', line 23 def tell @pos end |