Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stpettersens/node-magic-number
:seven: Node.js module to determine a file's type from its magic number.
https://github.com/stpettersens/node-magic-number
library magic module nodejs number
Last synced: about 1 month ago
JSON representation
:seven: Node.js module to determine a file's type from its magic number.
- Host: GitHub
- URL: https://github.com/stpettersens/node-magic-number
- Owner: stpettersens
- License: other
- Created: 2015-06-28T18:32:31.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-29T14:10:20.000Z (over 7 years ago)
- Last Synced: 2024-10-13T15:42:01.936Z (3 months ago)
- Topics: library, magic, module, nodejs, number
- Language: JavaScript
- Homepage: http://npmjs.com/package/magic-number
- Size: 47.9 KB
- Stars: 8
- Watchers: 1
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.markdown
- License: LICENSE
Awesome Lists containing this project
README
#### Magic-number
[![Build Status](https://travis-ci.org/stpettersens/node-magic-number.svg?branch=master)](https://travis-ci.org/stpettersens/node-magic-number) [![npm version](https://badge.fury.io/js/magic-number.svg)](http://npmjs.org/package/magic-number) [![Development Dependency Status](https://david-dm.org/stpettersens/node-magic-number/dev-status.png?theme=shields.io)](https://david-dm.org/stpettersens/node-magic-number?type=dev)
Node.js module to determine a file's type from its magic number.
Use from JavaScript:
```js
var magic = require('magic-number');
magic.detectFile('file.zip'); // ==> 'application/zip'
magic.detectFile('file.7z'); // ==> 'application/x-7z-compressed'
```Use from [TypeScript](http://www.typescriptlang.org):
```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.