fnout

1.1.0 • Public • Published

fnout

MIT licensed js-standard-style Coverage Status Build Status

fnout (file snout) lets you find what the contents of files are: in particular, whether they're executable or not.

Usage

const fnout = require('fnout')
 
var buf = new Buffer('#!/bin/bash')
fnout(buf).then((res) => {
  // res = {ext: 'sh', mime: 'application/x-sh', linuxExecutable: true, macExecutable: true}
})
 
fnout.path('path/to/App.dmg').then((res) => {
  // res = {ext: 'dmg', mime: 'application/x-apple-diskimage'}
})

fnout expects a node.js Buffer and returns a Promise which resolves to an object of the following shape:

{
  ext: '', // typical file extension, might be empty,
  mime: '', // mime-type, might fall back to `application/octet-stream`
  macExecutable: true, // truthy if can be executed on OSX
  linuxExecutable: true, // truthy if can be executed on Linux
}

fnout.path takes a path and an optional readHeader function. The readHeader function should take a path and return the first 262 bytes of the file.

Providing your own readHeader function is especially useful if you're not working off the disk, but reading from an archive for example.

Readme

Keywords

Package Sidebar

Install

npm i fnout

Weekly Downloads

2

Version

1.1.0

License

MIT

Last publish

Collaborators

  • fasterthanlime