Class: OpenDal::IO

Inherits:
Object
  • Object
show all
Defined in:
lib/opendal_ruby/io.rb

Instance Method Summary collapse

Instance Method Details

#eofBoolean Also known as: eof?

Checks if the stream is at the end of the file.

Returns:

  • (Boolean)


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

#lengthInteger Also known as: size

Returns the total length of the stream.

Returns:

  • (Integer)


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.

Parameters:

  • new_position (Integer)


44
45
46
# File 'lib/opendal_ruby/io.rb', line 44

def pos=(new_position)
  seek(new_position, ::IO::SEEK_SET)
end

#readlinesArray<String>

Reads all lines from the stream into an array.

Returns:

  • (Array<String>)

Raises:

  • (EOFError)

    when the end of the file is reached.



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

#rewindObject

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