Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working for txt file #27

Open
boris-petrov opened this issue Aug 4, 2017 · 2 comments
Open

Not working for txt file #27

boris-petrov opened this issue Aug 4, 2017 · 2 comments

Comments

@boris-petrov
Copy link

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
Copy link
Author

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?

@j256
Copy link
Owner

j256 commented Jul 10, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants