magic-number
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/magic-number package

0.1.6 • Public • Published

Magic-number

Build Status npm version Development Dependency Status

Node.js module to determine a file's type from its magic number.

Use from JavaScript:

var magic = require('magic-number');
magic.detectFile('file.zip'); // ==> 'application/zip'
magic.detectFile('file.7z');  // ==> 'application/x-7z-compressed'

Use from TypeScript:

/// <require path="typings/magic-number.d.ts" />
import magic = require('magic-number');
magic.detectFile('file.zip'); // ==> 'application/zip'
magic.detectFile('file.7z');  // ==> 'application/x-7z-compressed'

Methods:

magic.detectFile(file: string): string

Parameter file is path string for the file to test.

magic.detectType(data: any): string

Parameter data is binary data for the file to test.

Returns a MIME type for the tested file, 'unknown' if file type is not detected or message when file doesn't exist.

Package Sidebar

Install

npm i magic-number

Weekly Downloads

3,204

Version

0.1.6

License

MIT

Last publish

Collaborators

  • stpettersens