simplemagic icon indicating copy to clipboard operation
simplemagic copied to clipboard

Not working for txt file

Open boris-petrov opened this issue 8 years ago • 2 comments

Hi, I'm trying the library like this:

ContentInfoUtil contentInfoUtil = new ContentInfoUtil("/home/boris/.magic.mime");
ContentInfo info = contentInfoUtil.findMatch(path.toFile());

path is just a Path to a small text file named /tmp/PFZ6827520388559156905.txt with contents some text. If I'm using the built-in magic.mime file (i.e. I remove the argument to the constructor), info is null. If I use my magic.mime file (which I got from cloning https://github.com/file/file/ and concatenating all files in magic/Magdir) - info is not null, but rather: (NES, type OTHER, msg '(NES 2.0): 32x16k PRG, 116x8k CHR [V-mirror] [Trainer]' (that's the toString) and the mime type is null.

I'm not sure what's going on and what I'm doing wrong. It also doesn't work for .ods file (application/vnd.oasis.opendocument.spreadsheet), .docx (application/vnd.openxmlformats-officedocument.wordprocessingml.document, it returns application/zip), etc. For all of these the file command works fine. Where am I making a mistake? Isn't this library supposed to return the same things as the file command?

boris-petrov avatar Aug 04 '17 10:08 boris-petrov

Actually now I tried using the constructor which accepts an ErrorCallBack argument - and there are a million errors when parsing the magic.mime file that I've made using the steps I mentioned above. I'm not sure where can I get a working magic.mime file from. Can you please elaborate on this also?

boris-petrov avatar Sep 13 '17 14:09 boris-petrov

The file command has additional checking that is not magic number based. For example the ods files are zip files. To understand that they are spreadsheets requires opening up the zip file and interrogating its contents. This is same for text files which have no magic numbers. That said, I have a todo entry to start adding these specific type investigations.

j256 avatar Jul 10 '18 18:07 j256