Filetypes is a library that helps you guess the file and mine types of files using magic numbers
npm install filetypesSmall and dependency free Javascript library to infer file type and MIME type checking the magic numbers#Magic_numbers_in_files) signature of a file or buffer.
This is a Javascript port from filetype Go package.
Features
--------
- Simple and friendly API
- Supports a wide range of file types
- Provides file extension and MIME type inference
- File discovery by extension or MIME type
- File discovery by kind (image, video, audio...)
- Only first 261 bytes representing the max file header is required, so you can just [pass a list of bytes]
- Dependency free
- Cross-platform file recognition
Installation
------------
npm install filetypes
API
---
TODO
Examples
--------
#### Simple file type checking
``javascript
const FileTypes = require('filetypes');
//Just Check extension
let extension = FileTypes.guessMineType('Nicki Minaj - Anaconda.mp4');
/**
{ name: 'mp4',
mine: 'video/mp4',
extension: 'mp4',
match: [Function: match] }
*/
//Check extension and Magic_numbers in file;
let extension = FileTypes.guessMineType('../path/to/Nicki Minaj - Anaconda.mp4', true);
//Check if extension is Supported
FileTypes.isMineSupported("mp4")
//true
FileTypes.isMineSupported("xxs")
//false
`
#### collective type checking
`javascript
let { isAudio, isImage, isArchive, isFont, isVideo } = require('filetypes');
isAudio('../path/to/Nicki Minaj - Anaconda.mp4')
//false
isVideo('../path/to/Nicki Minaj - Anaconda.mp4')
//true
`
Supported types
---------------
#### Image
- jpg - image/jpegimage/png
- png - image/gif
- gif - image/webp
- webp - image/x-canon-cr2
- cr2 - image/tiff
- tif - image/bmp
- bmp - image/vnd.ms-photo
- jxr - image/vnd.adobe.photoshop
- psd - image/x-icon
- ico -
#### Video
- mp4 - video/mp4video/x-m4v
- m4v - video/x-matroska
- mkv - video/webm
- webm - video/quicktime
- mov - video/x-msvideo
- avi - video/x-ms-wmv
- wmv - video/mpeg
- mpg - video/x-flv
- flv -
#### Audio
- mid - audio/midiaudio/mpeg
- mp3 - audio/m4a
- m4a - audio/ogg
- ogg - audio/x-flac
- flac - audio/x-wav
- wav - audio/amr
- amr -
#### Archive
- epub - application/epub+zipapplication/zip
- zip - application/x-tar
- tar - application/x-rar-compressed
- rar - application/gzip
- gz - application/x-bzip2
- bz2 - application/x-7z-compressed
- 7z - application/x-xz
- xz - application/pdf
- pdf - application/x-msdownload
- exe - application/x-shockwave-flash
- swf - application/rtf
- rtf - application/octet-stream
- eot - application/postscript
- ps - application/x-sqlite3
- sqlite - application/x-nintendo-nes-rom
- nes - application/x-google-chrome-extension
- crx - application/vnd.ms-cab-compressed
- cab - application/x-deb
- deb - application/x-unix-archive
- ar - application/x-compress
- Z - application/x-lzip
- lz -
#### Font
- woff - application/font-woffapplication/font-woff
- woff2 - application/font-sfnt
- ttf - application/font-sfnt`
- otf -
License
-------
MIT - Geoff Mureithi
Lots of ideas borrowed Tomas Aparicio