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.
4 5 6 7 |
# File 'lib/zip_tricks/write_and_tell.rb', line 4 def initialize(io) @io = io @pos = 0 end |
Instance Method Details
#<<(bytes) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/zip_tricks/write_and_tell.rb', line 9 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
17 18 19 |
# File 'lib/zip_tricks/write_and_tell.rb', line 17 def advance_position_by(num_bytes) @pos += num_bytes end |
#tell ⇒ Object
21 22 23 |
# File 'lib/zip_tricks/write_and_tell.rb', line 21 def tell @pos end |