Module: XRay::Helper::FileReader

Extended by:
FileReader
Included in:
FileReader, Runner
Defined in:
lib/helper/file_reader.rb

Instance Method Summary collapse

Instance Method Details

#readfile(path, opt = {}) ⇒ Object

auto detect file encoding and read it. return with an array containing string and encoding



11
12
13
14
15
16
17
18
# File 'lib/helper/file_reader.rb', line 11

def readfile(path, opt={})
  if File.readable?(path)
    bin = File.read(path).utf8!
    [bin, bin.former_enc ||'ascii-8bit' ]
  else
    raise ArgumentError.new("File is not readable!")
  end
end