Reputation: 1271
Hi I want to detect file types in my application. libmagic is an option to do that. But I do not intend to string compare, for example:
An mp3 file output using libmagic : Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 128 kbps, 44.1 kHz, JntStereo
Are there any other libraries for True File Type Detection?
Upvotes: 3
Views: 1901
Reputation: 179779
You incorrectly presume that the set of filetypes is enumerable. That's just not how files work. Your example about .mp3 files (audio) naturally leads to video. What is the relation between .AVI, .MKV, MPEG1, MPEG2 and MPEG4 video? You can't capture those relations in a single number.
Similarly, is a CD .ISO the same filetype as a DVD .ISO? Either you assign the same number of you don't. And I specifically wrote "you" in the previous sentence because the answer depends on whether you consider them the same.
Upvotes: 2
Reputation: 4915
You could try to implement this by own using File Signature Table
Example:
Hex Signature File Extension ASCII Signature, File Description
49 44 33 MP3 ID3
MPEG-1 Audio Layer 3 (MP3) audio file
43 44 30 30 31 ISO CD001
ISO-9660 CD Disc Image
This signature usually ...
Upvotes: 3