An async libmagic binding for node.js for detecting content types by data inspection
Installations
npm install mmmagic
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=4.0.0
Node Version
10.15.0
NPM Version
6.4.1
Score
99.1
Supply Chain
98.9
Quality
75.9
Maintenance
100
Vulnerability
80.9
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
C++ (67.93%)
JavaScript (27.99%)
Python (4.08%)
Developer
mscdex
Download Statistics
Total Downloads
12,895,114
Last Day
11,410
Last Week
69,290
Last Month
335,195
Last Year
4,219,905
GitHub Statistics
623 Stars
182 Commits
50 Forks
9 Watching
1 Branches
5 Contributors
Bundle Size
790.00 B
Minified
446.00 B
Minified + Gzipped
Package Meta Information
Latest Version
0.5.3
Package Id
mmmagic@0.5.3
Size
512.52 kB
NPM Version
6.4.1
Node Version
10.15.0
Publised On
30 Apr 2019
Total Downloads
Cumulative downloads
Total Downloads
12,895,114
Last day
-12.9%
11,410
Compared to previous day
Last week
-18.4%
69,290
Compared to previous week
Last month
-22.4%
335,195
Compared to previous month
Last year
96.8%
4,219,905
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
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:
1 var Magic = require('mmmagic').Magic; 2 3 var magic = new Magic(); 4 magic.detectFile('node_modules/mmmagic/build/Release/magic.node', function(err, result) { 5 if (err) throw err; 6 console.log(result); 7 // output on Windows with 32-bit node: 8 // PE32 executable (DLL) (GUI) Intel 80386, for MS Windows 9 });
- Get mime type for a file:
1 var mmm = require('mmmagic'), 2 Magic = mmm.Magic; 3 4 var magic = new Magic(mmm.MAGIC_MIME_TYPE); 5 magic.detectFile('node_modules/mmmagic/build/Release/magic.node', function(err, result) { 6 if (err) throw err; 7 console.log(result); 8 // output on Windows with 32-bit node: 9 // application/x-dosexec 10 });
- Get mime type and mime encoding for a file:
1 var mmm = require('mmmagic'), 2 Magic = mmm.Magic; 3 4 var magic = new Magic(mmm.MAGIC_MIME_TYPE | mmm.MAGIC_MIME_ENCODING); 5 // the above flags can also be shortened down to just: mmm.MAGIC_MIME 6 magic.detectFile('node_modules/mmmagic/build/Release/magic.node', function(err, result) { 7 if (err) throw err; 8 console.log(result); 9 // output on Windows with 32-bit node: 10 // application/x-dosexec; charset=binary 11 });
- Get general description of the contents of a Buffer:
1 var Magic = require('mmmagic').Magic; 2 3 var magic = new Magic(), 4 buf = new Buffer('import Options\nfrom os import unlink, symlink'); 5 6 magic.detect(buf, function(err, result) { 7 if (err) throw err; 8 console.log(result); 9 // output: Python script, ASCII text executable 10 });
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. IfmagicSource
is not a string and notfalse
, the bundled magic file will be used. IfmagicSource
isfalse
, mmmagic will default to searching for a magic file to use (order of magic file searching:MAGIC
env var -> various file system paths (seeman file
)). flags is a bitmask with the following valid values (available as constants onrequire('mmmagic')
):- MAGIC_NONE - No flags set
- MAGIC_DEBUG - Turn on debugging
- MAGIC_SYMLINK - Follow symlinks (default for non-Windows)
- MAGIC_DEVICES - Look at the contents of devices
- MAGIC_MIME_TYPE - Return the MIME type
- MAGIC_CONTINUE - Return all matches (returned as an array of strings)
- MAGIC_CHECK - Print warnings to stderr
- MAGIC_PRESERVE_ATIME - Restore access time on exit
- MAGIC_RAW - Don't translate unprintable chars
- MAGIC_MIME_ENCODING - Return the MIME encoding
- MAGIC_MIME - (MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING)
- MAGIC_APPLE - Return the Apple creator and type
- MAGIC_NO_CHECK_TAR - Don't check for tar files
- MAGIC_NO_CHECK_SOFT - Don't check magic entries
- MAGIC_NO_CHECK_APPTYPE - Don't check application type
- MAGIC_NO_CHECK_ELF - Don't check for elf details
- MAGIC_NO_CHECK_TEXT - Don't check for text files
- MAGIC_NO_CHECK_CDF - Don't check for cdf files
- MAGIC_NO_CHECK_TOKENS - Don't check tokens
- MAGIC_NO_CHECK_ENCODING - Don't check text encodings
-
detectFile(< String >path, < Function >callback) - (void) - Inspects the file pointed at by path. The callback receives two arguments: an < Error > object in case of error (null otherwise), and a < String > containing the result of the inspection.
-
detect(< Buffer >data, < Function >callback) - (void) - Inspects the contents of data. The callback receives two arguments: an < Error > object in case of error (null otherwise), and a < String > containing the result of the inspection.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-01-13
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to mmmagic
@types/mmmagic
TypeScript definitions for mmmagic
stream-mmmagic
sniff the start of a stream (non-destructively) to detect the file type and encoding
@picturae/mmmagic
An async libmagic binding for node.js for detecting content types by data inspection
mmmagic-type
Detect file type with [mmmagic](https://github.com/mscdex/mmmagic) and [mime](https://github.com/broofa/node-mime).