Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/sixarm_ruby_magic_number_type/file.rb

Class Method Summary collapse

Class Method Details

.magic_number_type(file_name) ⇒ Object

Detect the file’s data type by opening the file then using IO#magic_number_type to read the first bits.

Return a magic number type symbol, e.g. :bitmap, :jpg, etc.

Example:

puts File.magic_number_type("test.ps") => :postscript

See

- IO#MagicNumberTypeHash
- IO#magic_number_type


17
18
19
20
21
22
# File 'lib/sixarm_ruby_magic_number_type/file.rb', line 17

def self.magic_number_type(file_name)
  f = File.open(file_name,"rb")
  type = f.magic_number_type
  f.close
  return type
end