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
- <input disabled="" type="checkbox"> .svg
- <input disabled="" type="checkbox"> .tif
- <input disabled="" type="checkbox"> .psd
- Tar
- <input disabled="" type="checkbox"> .tar
- <input disabled="" type="checkbox"> .gzip
- <input disabled="" type="checkbox"> .zip
- <input disabled="" type="checkbox"> .rar
- PE file
- <input disabled="" type="checkbox"> .exe
- <input disabled="" type="checkbox"> .msi
- <input disabled="" type="checkbox"> .apk
- <input disabled="" type="checkbox"> .ipa
- Text
- <input disabled="" type="checkbox"> .xml
- <input disabled="" type="checkbox"> .html
- <input disabled="" type="checkbox"> .json
- Media
- <input disabled="" type="checkbox"> .mp3
- <input disabled="" type="checkbox"> .mp4
- <input disabled="" type="checkbox"> .avi