An async libmagic binding for node.js for detecting content types by data inspection
npm install mmmagic2
npm install mmmagic2
`
I am not maintaining this
This fork is made in order to merge/apply patches that others have made (pull requests are open btw) in order to fix macOS builds and node v20+ builds since the original appears to be unmaintained.
This fork is functionally identical to the original
The differences are the following:
- this readme file
- package name (changed from mmmagic to mmmagic2 to be made into a different package on NPM)
- repo URL in the package.json file so that the NPM package links to this github repository (reason: patches can be applied)
Original repo here -> https://github.com/mscdex/mmmagic
Original description is found below
------------------
Description
===========
An async libmagic binding for node.js for detecting content types by data inspection.


Requirements
============
* node.js -- v4.0.0 or newer
Install
=======
npm install mmmagic
Examples
========
* Get general description of a file:
`javascript
var Magic = require('mmmagic').Magic;
var magic = new Magic();
magic.detectFile('node_modules/mmmagic/build/Release/magic.node', function(err, result) {
if (err) throw err;
console.log(result);
// output on Windows with 32-bit node:
// PE32 executable (DLL) (GUI) Intel 80386, for MS Windows
});
`
* Get mime type for a file:
`javascript
var mmm = require('mmmagic'),
Magic = mmm.Magic;
var magic = new Magic(mmm.MAGIC_MIME_TYPE);
magic.detectFile('node_modules/mmmagic/build/Release/magic.node', function(err, result) {
if (err) throw err;
console.log(result);
// output on Windows with 32-bit node:
// application/x-dosexec
});
`
* Get mime type and mime encoding for a file:
`javascript
var mmm = require('mmmagic'),
Magic = mmm.Magic;
var magic = new Magic(mmm.MAGIC_MIME_TYPE | mmm.MAGIC_MIME_ENCODING);
// the above flags can also be shortened down to just: mmm.MAGIC_MIME
magic.detectFile('node_modules/mmmagic/build/Release/magic.node', function(err, result) {
if (err) throw err;
console.log(result);
// output on Windows with 32-bit node:
// application/x-dosexec; charset=binary
});
`
* Get general description of the contents of a Buffer:
`javascript
var Magic = require('mmmagic').Magic;
var magic = new Magic(),
buf = new Buffer('import Options\nfrom os import unlink, symlink');
magic.detect(buf, function(err, result) {
if (err) throw err;
console.log(result);
// output: Python script, ASCII text executable
});
`
API
===
Magic methods
-------------
(constructor)([< _mixed_ >magicSource][, < _Integer_ >flags]) - Creates and returns a new Magic instance. magicSource (if specified) can either be a path string that points to a (compatible) magic file to use or* it can be a _Buffer_ containing the contents of a (compatible) magic file. If magicSource is not a string and not false, the bundled magic file will be used. If magicSource is false, mmmagic will default to searching for a magic file to use (order of magic file searching: MAGIC env var -> various file system paths (see man file)). flags is a bitmask with the following valid values (available as constants on require('mmmagic')`):