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

Implement libmagic in JS #68

Closed
mifi opened this issue Nov 22, 2016 · 8 comments
Closed

Implement libmagic in JS #68

mifi opened this issue Nov 22, 2016 · 8 comments

Comments

@mifi
Copy link
Sponsor Contributor

mifi commented Nov 22, 2016

The holy grail would be to build a JS parser for the magic database from libmagic and bundle it in the module, so we don't have to reimplement all the format parsing manually in code.
libmagic is the database used by the "file" command in unix. However this is not trivial.

See:

@sindresorhus
Copy link
Owner

This is not something I intend to work on, but I asked for this issue to be opened in case someone wants a good challenge 🦄🤘

@hollowdoor
Copy link

Out of curiosity would you want the database downloaded in a build step? Then parse it into js arrays, or let be to be parsed as a stream? Or downloaded post install then parsed in the user program?

Not saying I'm going to do it. I'm just curious. :)

@mifi
Copy link
Sponsor Contributor Author

mifi commented Feb 21, 2018

I think it should be compiled to js for maximum speed. I tried to just make a simple runtime parser that loads the magdir files and parses them and then runs those rules on input files, but it was quite slow. And some of the rules in libmagic are quite obscure and tricky to implement correctly. And the detection of many popular file types uses these complicated rules... so i gave up 😅

@hollowdoor
Copy link

Would the ideal js output be a structure that was meant to be consumed, or a full process with logic?

And some of the rules in libmagic are quite obscure and tricky to implement correctly

Looking at the magic database I would agree.

@aaronArinder
Copy link

aaronArinder commented Apr 12, 2019

There's another project, mmmagic, that uses node addons to keep from re-implementing everything in magic.mgc. Pretty sweet stuff! The only problem, though, is that it says it uses file 5.32, but the md5sums from my in-system magic.mgc (compiled from file 5.32) and the project's magic.mgc are different. Still, gives some indication of how to do it.

@mifi
Copy link
Sponsor Contributor Author

mifi commented Apr 13, 2019

Cool! Great find @aaronArinder !
Another problem is that if using that lib, it will only work in Node.js and not in the browser or react native like file-type does.

@mceachen
Copy link
Contributor

FYI, file doesn't support many of the file types that this library does (including raw image types)

@sindresorhus
Copy link
Owner

I'm gonna close this as I don't see enough value in adopting libmagic. This package already covers most popular formats now, without all the legacy of libmagic, and it also works in the browser.

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

No branches or pull requests

5 participants