Method: OpenC3::BufferedFile#seek

Defined in:
lib/openc3/io/buffered_file.rb,
ext/openc3/ext/buffered_file/buffered_file.c

#seek(*args) ⇒ Object

Seek to a given file position



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/openc3/io/buffered_file.rb', line 81

def seek(*args)
  case args.length
  when 1
    amount = args[0]
    whence = IO::SEEK_SET
  when 2
    amount = args[0]
    whence = args[1]
  else
    # Invalid number of arguments given - let super handle
    return super(*args)
  end

  if whence == IO::SEEK_CUR
    buffer_index = @buffer_index + amount
    if (buffer_index >= 0) && (buffer_index < @buffer.length)
      @buffer_index = buffer_index
      return 0
    end
    super(self.pos, IO::SEEK_SET)
  end

  @buffer.clear
  @buffer_index = 0
  return super(*args)
end