npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mmmagic

v0.5.3

Published

An async libmagic binding for node.js for detecting content types by data inspection

Downloads

454,172

Readme

Description

An async libmagic binding for node.js for detecting content types by data inspection.

Build Status Build status

Requirements

Install

npm install mmmagic

Examples

  • Get general description of a file:
  var Magic = require('mmmagic').Magic;

  var magic = new Magic();
  magic.detectFile('node_modules/mmmagic/build/Release/magic.node', function(err, result) {
      if (err) throw err;
      console.log(result);
      // output on Windows with 32-bit node:
      //    PE32 executable (DLL) (GUI) Intel 80386, for MS Windows
  });
  • Get mime type for a file:
  var mmm = require('mmmagic'),
      Magic = mmm.Magic;

  var magic = new Magic(mmm.MAGIC_MIME_TYPE);
  magic.detectFile('node_modules/mmmagic/build/Release/magic.node', function(err, result) {
      if (err) throw err;
      console.log(result);
      // output on Windows with 32-bit node:
      //    application/x-dosexec
  });
  • Get mime type and mime encoding for a file:
  var mmm = require('mmmagic'),
      Magic = mmm.Magic;

  var magic = new Magic(mmm.MAGIC_MIME_TYPE | mmm.MAGIC_MIME_ENCODING);
  // the above flags can also be shortened down to just: mmm.MAGIC_MIME
  magic.detectFile('node_modules/mmmagic/build/Release/magic.node', function(err, result) {
      if (err) throw err;
      console.log(result);
      // output on Windows with 32-bit node:
      //    application/x-dosexec; charset=binary
  });
  • Get general description of the contents of a Buffer:
  var Magic = require('mmmagic').Magic;

  var magic = new Magic(),
        buf = new Buffer('import Options\nfrom os import unlink, symlink');
  
  magic.detect(buf, function(err, result) {
      if (err) throw err;
      console.log(result);
      // output: Python script, ASCII text executable
  });

API

Magic methods

  • (constructor)([< mixed >magicSource][, < Integer >flags]) - Creates and returns a new Magic instance. magicSource (if specified) can either be a path string that points to a (compatible) magic file to use or it can be a Buffer containing the contents of a (compatible) magic file. If magicSource is not a string and not false, the bundled magic file will be used. If magicSource is false, mmmagic will default to searching for a magic file to use (order of magic file searching: MAGIC env var -> various file system paths (see man file)). flags is a bitmask with the following valid values (available as constants on require('mmmagic')):

    • MAGIC_NONE - No flags set
    • MAGIC_DEBUG - Turn on debugging
    • MAGIC_SYMLINK - Follow symlinks (default for non-Windows)
    • MAGIC_DEVICES - Look at the contents of devices
    • MAGIC_MIME_TYPE - Return the MIME type
    • MAGIC_CONTINUE - Return all matches (returned as an array of strings)
    • MAGIC_CHECK - Print warnings to stderr
    • MAGIC_PRESERVE_ATIME - Restore access time on exit
    • MAGIC_RAW - Don't translate unprintable chars
    • MAGIC_MIME_ENCODING - Return the MIME encoding
    • MAGIC_MIME - (MAGIC_MIME_TYPE | MAGIC_MIME_ENCODING)
    • MAGIC_APPLE - Return the Apple creator and type
    • MAGIC_NO_CHECK_TAR - Don't check for tar files
    • MAGIC_NO_CHECK_SOFT - Don't check magic entries
    • MAGIC_NO_CHECK_APPTYPE - Don't check application type
    • MAGIC_NO_CHECK_ELF - Don't check for elf details
    • MAGIC_NO_CHECK_TEXT - Don't check for text files
    • MAGIC_NO_CHECK_CDF - Don't check for cdf files
    • MAGIC_NO_CHECK_TOKENS - Don't check tokens
    • MAGIC_NO_CHECK_ENCODING - Don't check text encodings
  • detectFile(< String >path, < Function >callback) - (void) - Inspects the file pointed at by path. The callback receives two arguments: an < Error > object in case of error (null otherwise), and a < String > containing the result of the inspection.

  • detect(< Buffer >data, < Function >callback) - (void) - Inspects the contents of data. The callback receives two arguments: an < Error > object in case of error (null otherwise), and a < String > containing the result of the inspection.