Class: OpenDal::IO
- Inherits:
-
Object
- Object
- OpenDal::IO
- Defined in:
- lib/opendal_ruby/io.rb
Instance Method Summary collapse
-
#eof ⇒ Boolean
(also: #eof?)
Checks if the stream is at the end of the file.
-
#length ⇒ Integer
(also: #size)
Returns the total length of the stream.
-
#pos=(new_position) ⇒ Object
Sets the file position to
new_position. -
#readlines ⇒ Array<String>
Reads all lines from the stream into an array.
-
#rewind ⇒ Object
Rewinds the stream to the beginning.
Instance Method Details
#eof ⇒ Boolean Also known as: eof?
Checks if the stream is at the end of the file.
52 53 54 55 56 |
# File 'lib/opendal_ruby/io.rb', line 52 def eof position = tell seek(0, ::IO::SEEK_END) tell == position end |
#length ⇒ Integer Also known as: size
Returns the total length of the stream.
62 63 64 65 66 |
# File 'lib/opendal_ruby/io.rb', line 62 def length current_position = tell seek(0, ::IO::SEEK_END) tell.tap { self.pos = current_position } end |
#pos=(new_position) ⇒ Object
Sets the file position to new_position.
44 45 46 |
# File 'lib/opendal_ruby/io.rb', line 44 def pos=(new_position) seek(new_position, ::IO::SEEK_SET) end |
#readlines ⇒ Array<String>
Reads all lines from the stream into an array.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/opendal_ruby/io.rb', line 25 def readlines results = [] loop do results << readline rescue EOFError break end results end |
#rewind ⇒ Object
Rewinds the stream to the beginning.
38 39 40 |
# File 'lib/opendal_ruby/io.rb', line 38 def rewind seek(0, ::IO::SEEK_SET) end |