JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 681
  • Score
    100M100P100Q98890F

libmagic bindings for node.js. Includes a file(1) wrapper as alternative.

Package Exports

  • mime-magic

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mime-magic) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

About

MIME type detection library for node.js. Unlike the existing mime module, mime-magic does not return the type by interpreting the file extension. Instead it uses the libmagic(3) library that does it properly.

Currently it provides just a simple file(1) wrapper to get the things moving, but in the long run, the purpose of this module is to provide proper node.js libmagic bindings.

Installation

Either manually clone this repository into your node_modules directory, or the recommended method:

npm install mime-magic

Usage mode

var mime = require('mime-magic');

mime.fileWrapper('/path/to/foo.pdf', function (err, mime) {
    if (err) {
        console.error(err.message); // ERROR: cannot open `/path/to/foo.pdf' (No such file or directory)
    } else {
        console.log('Detected mime type: %s', mime); // application/pdf
    }
});

Passing relative paths is supported. The fileWrapper uses child_process.exec behind the scenes, therefore the err argument contains the information returned by the exec method itself plus the error message returned by file(1). The module was developed against file 5.03 which sends the error message via STDOUT. An unfortunate choice from the developer, but if your file utility behaves differently, then you may not get the exact error message.