Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

buffer-signature

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buffer-signature

Get the mimetype of a buffer based on its contents

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
1K
-2.7%
Maintainers
1
Weekly downloads
 
Created
Source

buffer-signature

Get the mimetype of a buffer based on its contents.

Data for this script was generated from: http://en.wikipedia.org/wiki/List_of_file_signatures

Additional support for mp4 and mov formats from @cmd430

This is a fork of file-signature by @leahcimic.

To match against any file format, you'll need a minimum of 22 bytes from the start of the file.

Example use:


var identifyBuffer = require('buffer-signature').identify;
console.log(identifyBuffer(fs.readFileSync('path/to/file.jpg')));

var identifyStream = require('buffer-signature').identifyStream;
fs.createReadStream('path/to/file.jpg').pipe(identifyStream(info => {
  console.log(info)
}).pipe(…whatever else you want to do with the data…)

// outputs:
// {
//   description: 'A commonly used method of lossy compression for digital photography (image).',
//   mimeType: 'image/jpg'
//   extensions: ['jpg', 'jpeg']
// }

Changes form file-signature

  • Made identify take a buffer instead of a filename
  • Added identifyStream
  • Refreshed magic number list from Wikipedia and fixed signature matcher to support offsets
  • Added a bunch of missing mimetypes
  • Ditched bespoke buffer equality function for Buffer.equals

Keywords

mime

FAQs

Package last updated on 24 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts