Class: FileOption

Inherits:
Slop::Option
  • Object
show all
Defined in:
lib/ermir/argv_parser.rb

Instance Method Summary collapse

Instance Method Details

#call(value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ermir/argv_parser.rb', line 13

def call(value)
  begin
    obj = File.open(value, 'rb').each_byte.to_a.pack("C*")
    unless Utils.stream_header_valid?(obj)
      Utils.error_and_abort!(Errors::FILE_CORRUPTED_ERROR, "--file")
    end
    obj
  rescue Errno::ENOENT, Errno::EACCES => e
    Utils.error_and_abort!(Errors::FILE_PATH_ERROR, "--file", e.to_s)
  end
end