Method: MemFs::IO.read

Defined in:
lib/memfs/io.rb

.read(path, *args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/memfs/io.rb', line 17

def self.read(path, *args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  options = {
    mode: File::RDONLY,
    encoding: nil,
    open_args: nil
  }.merge(options)
  open_args = options[:open_args] ||
              [options[:mode], encoding: options[:encoding]]

  length, offset = args

  file = open(path, *open_args)
  file.seek(offset || 0)
  file.read(length)
ensure
  file.close if file
end