Module: MemFs::IO::ClassMethods

Included in:
File
Defined in:
lib/memfs/io.rb

Instance Method Summary collapse

Instance Method Details

#read(path, *args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/memfs/io.rb', line 7

def 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