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

Info Needed: Why Partial Match and what it does? #12

Closed
se7en007 opened this issue Aug 13, 2016 · 11 comments
Closed

Info Needed: Why Partial Match and what it does? #12

se7en007 opened this issue Aug 13, 2016 · 11 comments

Comments

@se7en007
Copy link

Hi Gray,
First of all, thank you for providing this small and to the point library. Amazing.

I have been checking the code and it looks like the Mime Type that is returned could be only a partial match:- MagicEntries.java:140.

Problem:- I am using your library to check mime type of the image file and then processing according to the content type(JPEG/PNG). Now, if partial match makes an image(unknown extension) match to of JPEG/PNG/any other common image format, the processing could end up being incorrect.

I have two questions to solve this problem :-

a. What was the need of Partial Match?
b. When Partial Match happens, what happens to ContentType - Multiple Values/Single Value always?

My Guess:
MIME information is stored as few bytes at the start of the file. You have a possibly a trie with all mime types. You are checking for mime of file in the trie and if the mime is not found, but starting few bytes of the file matched to a path in the trie, you append all leaf nodes under the path in that tree (Mime type starting with the same prefix as of mime of the file).

FYI:
Documentation in github wiki seems to point to urls which redirect to external websites.
Checked at http://www.redirect-checker.org/index.php

Output:

http://256.com
301 Moved Permanently
http://www.jinpai.com/Home/OnlineBid/buyout_details/mid/24379.html
200 OK

@j256
Copy link
Owner

j256 commented Sep 16, 2016

a. What was the need of Partial Match?

Sorry for the delay on this @se7en007 . The partial match is needed because in magic files, often there are multiple matches and later ones may be better. For example, SVG images are XML matches but the SVG+XML match is better.

@j256
Copy link
Owner

j256 commented Sep 16, 2016

Documentation in github wiki seems to point to urls which redirect to external websites.

I sold my 256.com domain a while back. I should have migrated all of those links to 256stuff.com. Which URL are you talking about that has out of date links?

@j256
Copy link
Owner

j256 commented Sep 16, 2016

b. When Partial Match happens, what happens to ContentType - Multiple Values/Single Value always?

It should return good information. Can you give me an example of where it doesn't?

@se7en007
Copy link
Author

se7en007 commented Sep 16, 2016

No worries for the delay.

The library gives partial match on webp files.

So, read from google docs that webp files are in RIFF container. If I run on webp files, it gives There was a partial match, RIFF, type OTHER, msg 'RIFF (little-endian) data'. This is also a feature request as enum com.j256.simplemagic.ContentType#WEBP is provided but it is not what returned but enum com.j256.simplemagic.ContentType#OTHER.

1472812600656_679_92337e55-d140-4da1-8c79-94582c05ad61_540x360.webp.zip

For now I am using workaround:

if(contentInfo.getName().equalsIgnoreCase("RIFF")) return ImageMimeType.WEBP;

@se7en007
Copy link
Author

At https://github.com/j256/simplemagic/wiki, only 2 links : central maven repository and github works. Rest all down.

@j256
Copy link
Owner

j256 commented Sep 19, 2016

Fixed thanks.

@j256
Copy link
Owner

j256 commented Sep 19, 2016

Hey, can you turn the WEBP request into another issue so I can track it right? Thanks.

@se7en007
Copy link
Author

Done and thank you. One question, will you release a new version of library, or just patched the current version to maven?

@j256
Copy link
Owner

j256 commented Sep 19, 2016

I've got a bad bug that I'm looking at now and I hope to release a new version once that's done.

On Sep 19, 2016, at 13:01, Saurabh Khanduja notifications@github.com wrote:

Done and thank you. One question, will you release a new version of library, or just patched the current version to maven?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

@se7en007
Copy link
Author

No hurries. Thank you once again.

@j256
Copy link
Owner

j256 commented Sep 20, 2016

1.7 has been released. http://repo1.maven.org/maven2/com/j256/simplemagic/simplemagic/1.7/

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