get-file-format
v1.0.3
Published
Detect the format of a file by looking at its magic number
Readme
get-file-format
Detect the format of a file by looking at its magic number
[!IMPORTANT] WIP: Check the tests for the current supported file types
Install
npm i get-file-formatUsage
const getFileFormat = require('get-file-format')
const buffer = require('./sample.png', { with: { type: 'binary' } })
const format = getFileFormat(buffer)
// pngIt can be used in combination with get-mime-type:
const getFileFormat = require('get-file-format')
const getMimeType = require('get-mime-type')
const buffer = require('./sample.png', { with: { type: 'binary' } })
const mimetype = getMimeType(getFileFormat(buffer))
// image/pngCLI
Also available via command line:
npm i get-file-format -g
gff ./sample.jpgOptions:
<path> Path to the file to inspect
--verbose, -v Print bytes and other info
--start, -s <byteStart> Start index of bytes to print in verbose mode
--length, -n <byteLength> Number of bytes to print in verbose mode
--help Print helpLicense
Apache-2.0
