For compatibility on both Mac OS X and Ubuntu Linux I used: file -mime -b 4 video/mp4; charsetbinary.
Since some types collide # we only test some types on basis of frequency: 0x08 (83 0x09 (5 # 0x02 (5 0x03 (3 0x04 (2 0x06 (2).
There must be a rubyesque tool similar to the unix file(1) command?
shrug* 0 string crush Crush archive jquery contact tabs plugin data # Squeeze It (.sqz) 0 string hlsqz Squeeze It archive data # sqwez 0 string sqwez sqwez archive data # HPack (.hpk) 0 string hpak HPack archive data # HAP 0 string x91x33HF HAP archive data # MD/mdcd.
This list is not exhaustive.This is regarding mime or content type, not file system classifications, such as directory, file, or socket.Ruby content-type mime-types file-type up vote 57 down vote, there is a ruby binding to libmagic that does what you need.Starting with version 4, the file command is not much more than a wrapper around the "magic" library.#0 string HA HA archive data, # 2 leshort 1 1 file, # 2 leshort 1 u files, # 4 byte 0x0f 0 first is type CPY # 4 byte 0x0f 1 first is type ASC # 4 byte 0x0f 2 first is type HSC.# file/libmagic does not current have support for ascii-string based # (offsets).Org.x 62 string writer Writer 68 byte!0x2e document 68 string.template template 68 string.global global document 62 string calc Calc 66 byte!0x2e spreadsheet 66 string.template template 62 string draw Draw 66 byte!0x2e document 66 string.template template 62 string impress Impress 69 byte!0x2e presentation 69 string.template.Nicole Beebe from The University of Texas at San Antonio posted samples of more than 32 file types at the Digital Corpora, which I used for verification and additional signatures.This library allows for the identification of a files likely mime content type.
Sceadan File Type Classifier.
# pre-posix "tar" archives are handled in the C code.
It is available as a gem named ruby-filemagic : gem install ruby-filemagic, require libmagic-dev.Archive data lh3!:mime application/x-lha 2 string -lh4- LHa (2.x) archive data lh4!:mime application/x-lha 2 string -lh5- LHa (2.x) archive data lh5!:mime application/x-lha 2 string -lh6- LHa (2.x) archive data lh6!:mime application/x-lha 2 string -lh7- LHa (2.x LHark archive data lh7!:mime application/x-lha 20 byte.Dll or msvcp60.dll is not in your Windows/System folder, get them from Microsoft, or (msvcrt.Forensic Computing: A Practitioner's Guide.# 0 string LBR archive data # # PMA (CP/M derivative of LHA) # 2 string -pm0- PMarc archive data pm0 2 string -pm1- PMarc archive data pm1 2 string -pm2- PMarc archive data pm2 2 string -pms- PMarc SFX archive (CP/M, DOS) 5 string.This table of file signatures (aka "magic numbers is a continuing work-in-progress.The identification of mime content type is based on a files filename extensions.0 string PAR0 PARity archive data 48 leshort 0 - Index file 48 leshort 0 - file number d # Felix von Leitner 0 string d8:announce BitTorrent file!:mime application/x-bittorrent # Atari MSA archive - Teemu Hukkanen 0 beshort 0x0e0f Atari MSA archive data 2 beshort.If you download the package as Zip files, then you must download and install the dependencies zip file yourself.I found shelling out to be the most reliable.