Method: File.magic_number_type

Defined in:
lib/file_signature.rb

.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 few bytes.

Return a magic number type symbol, e.g. :bitmap, :jpg, etc. Returns nil if the data type is unknown

Example:

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

See

- IO::MagicNumberTypeMap
- IO::MimeTypeMap
- IO#magic_number_type
- IO#mime_type
- File.mime_type


319
320
321
# File 'lib/file_signature.rb', line 319

def self.magic_number_type(file_name)
  File.open(file_name,"rb"){|f| f.magic_number_type }
end