buffer-file-signature
v1.1.1
Published
Determine file type based on signature
Downloads
82
Maintainers
Readme
buffer-file-signature
:hammer: So far it only detects popular image/audio/application types, new types will be added as time goes by and/or we have help.
This package is inspired by file-type and uses the file signature as the basis for determining its type.
why choose me?
- zero dependency
- detects quickly and synchronously
Install
Node.js
npm i buffer-file-signature
# or
yarn add buffer-file-signature
Usage
Detects by base64 ( only so far )
const file = BufferFileSignature.fromBase64('4AAQSkZJRgA...')
file.extension()
/*
example output: {
ext: 'jpg',
mime: 'image/jpeg',
types: ['jpg', 'jpeg', 'jfif']
}
*/
file.size()
/*
example output: 512000 // bytes
*/
Help method for formatting size
const file = BufferFileSignature.formatSize(512000)
/*
example output: 500 KB
*/