Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/katyo/node-mgc
Node libmagic addon (detects mime info by inspecting node buffer's data).
https://github.com/katyo/node-mgc
Last synced: 16 days ago
JSON representation
Node libmagic addon (detects mime info by inspecting node buffer's data).
- Host: GitHub
- URL: https://github.com/katyo/node-mgc
- Owner: katyo
- Created: 2012-09-20T06:57:52.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-09-21T06:33:50.000Z (over 12 years ago)
- Last Synced: 2024-10-30T16:12:08.538Z (2 months ago)
- Size: 321 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
Awesome Lists containing this project
README
* TODO Overview
This addon adds to node functionality of libmagic and `file` util.
Unlike to https://github.com/mscdex/mmmagic it:
+ Uses native installed libmagic
+ Support strings, node buffers and streams only
+ Operate absolutely thread-safe (although libmagic isn't thread-safe)* TODO Usage
: var MGC = require('mgc'); /* require module */
: var mgc = new MGC(flags); /* create new instance with flags (optional) */** Loading
*** Default database
: mgc.load(function(err){ /* load default .mgc databases */
: if(err) throw err;
: /* now mgc is ready for use */
: });*** Own .mgc databases
: mgc.load('/usr/share/file/magic.mgc:/home/user/magic.mgc',
: function(err){ /* load .mgc databases */
: if(err) throw err;
: /* now mgc is ready for use */
: });** Detecting
*** String and Buffer
: mgc.data(buf_or_str, function(err, desc){ /* gets description of data */
: if(err) throw err;
: console.log(desc);
: });*** Readable Stream
: var FS = require('fs');
: var stm = FS.createReadStream('path/to/file');
: mgc.wrap(stm);
: stm.on('magic', function(err, desc){ /* gets description of data */
: if(err) throw err;
: console.log(desc);
: });* TODO Specs
** Flags
Flags is a string of names, like this:
+ *debug, d* — turn on debugging
+ *type, t* — return the MIME type
+ *enc, c* — return the MIME encoding
+ *mime, m* — return the MIME type and encoding (same as t+c)
+ *all, a* — return all matches
+ *error, e* — handle ENOENT etc as real errorsFlags may be combined in any order and separated by +|,:
** Wrap
You can pass a minimal (for detecting) content length in bytes as second argument to *wrap* call.
By default it equals to 16 Kbytes.