npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

get-file-format

1.1.1

@educastellano

npmHomeSnykSocket
Downloads:7179
$ npm install get-file-format
DailyWeeklyMonthlyYearly

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-format

Usage

const getFileFormat = require('get-file-format')

const buffer = require('./sample.png', { with: { type: 'binary' } })

const format = getFileFormat(buffer)
// png

It 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/png

CLI

Also available via command line:

npm i get-file-format -g

gff ./sample.jpg

Options:

  <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 help

License

Apache-2.0