Skip to content

stpettersens/node-magic-number

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •