buffer-type
Detect content-type from Buffer data.
Install
$ npm install buffer-type
Usage
const bt = require('buffer-type');
const fs = require('fs');
const info = bt(fs.readFileSync(__dirname + '/logo.png'));
console.log(info);
// {
// type: 'image/png',
// extension: '.png',
// width: 618,
// height: 96,
// bit: 8, // bit depth
// color: 6,
// compression: 0,
// filter: 0,
// interlace: 0
// }
References
- http://www.onicos.com/staff/iz/formats/
- http://www.fastgraph.com/help/image_file_header_formats.html
- http://en.wikipedia.org/wiki/Portable_Network_Graphics
- http://en.wikipedia.org/wiki/Image_file_format
TODO
- Image
- [√] .png
- [√] .jpg
- [√] .bmp
- [√] .gif
- [√] .webp
- .svg
- .tif
- .psd
- Tar
- .tar
- .gzip
- .zip
- .rar
- PE file
- .exe
- .msi
- .apk
- .ipa
- Text
- .xml
- .html
- .json
- Media
- .mp3
- .mp4
- .avi