Confusion for mime files: magic, magic.mgc, magic.mime
Posted
by
Florence Foo
on Ask Ubuntu
See other posts from Ask Ubuntu
or by Florence Foo
Published on 2014-08-21T01:44:12Z
Indexed on
2014/08/21
4:31 UTC
Read the original article
Hit count: 773
I'm using Ubuntu. I'm trying to use ruby gem 'shared-mime-info' for an application I'm writing.
I understand that magic.mgc is a compiled version of magic file which has magic number definitions for the different file types.
BUT I don't understand why is it /usr/share/mime/magic is in binary format instead of just normal text file with each parameters separated by white space like everywhere else I'm finding on the internet when it's referencing this file?
The /usr/share/mime/magic has the word 'MIME-Magic' at the beginning of the file and prioritize the rest of the stuff like. So it doesn't look like magic.mgc at all.
[100:application/vnd.scribus]
>1=^@^KSCRIBUSUTF8
[90:application/vnd.stardivision.writer]
>2089=^@
shared-mime-info seems to want a magic file in the binary non compiled format as above and I wanted to add definition for DOCX but how does one update or generate this file without using a hex editor?
There is a reference to the magic file I found at: http://standards.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html
And it mention this file is updated with update-mime-database but what if I just want to add some new entry to it. hex editor?
Anyway I ended up using hexer to make a new magic file in ~/.local/share/mime/ with only the entry I wanted to add and the MIME-Magic header. Seems to work (assuming I will ever deal with docx for now).
00000000: 4d 49 4d 45 2d 4d 61 67 69 63 00 0a 5b 36 30 3a MIME-Magic..[60:
00000010: 61 70 70 6c 69 63 61 74 69 6f 6e 2f 76 6e 64 2e application/vnd.
00000020: 6f 70 65 6e 78 6d 6c 66 6f 72 6d 61 74 73 2d 6f openxmlformats-o
00000030: 66 66 69 63 65 64 6f 63 75 6d 65 6e 74 2e 77 6f fficedocument.wo
00000040: 72 64 70 72 6f 63 65 73 73 69 6e 67 6d 6c 2e 64 rdprocessingml.d
00000050: 6f 63 75 6d 65 6e 74 5d 0a 3e 30 3d 00 08 50 4b ocument].>0=..PK
00000060: 03 04 14 00 06 00 0a -- -- -- -- -- -- -- -- -- .......---------
© Ask Ubuntu or respective owner