GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - mrexroad/mmmagic: An async libmagic binding for node.js for detecting content types by data inspection

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

15 Commits
15 Commits

Folders and files

NameName
Last commit message
Last commit date
deps/libmagic
deps/libmagic
 
 
magic
magic
 
 
win32
win32
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.js
build.js
 
 
index.js
index.js
 
 
magic.cc
magic.cc
 
 
package.json
package.json
 
 
wscript
wscript
 
 

Repository files navigation

Description

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

Requirements

  • node.js -- v0.6.0 or newer
  • zlib (*nix only)

Install

npm install mmmagic

Examples

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

  var magic = new Magic();
  magic.detectFile(__dirname + '/node_modules/mmmagic/wscript', function(err, result) {
      if (err) throw err;
      console.log(result);
      // output: Python script, ASCII text executable
  });
  • Get mime type for a file:
  var mmm = require('mmmagic'),
        Magic = mmm.Magic;

  var magic = new Magic(mmm.MAGIC_MIME_TYPE);
  magic.detectFile(__dirname + '/node_modules/mmmagic/wscript', function(err, result) {
      if (err) throw err;
      console.log(result);
      // output: text/x-python
  });
  • 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(__dirname + '/node_modules/mmmagic/wscript', function(err, result) {
      if (err) throw err;
      console.log(result);
      // output: text/x-python; charset=us-ascii
  });
  • 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)([<String>magicPath][, <Integer>flags]) - Creates and returns a new Magic instance. magicPath is an optional path string that points to a particular magic file to use (order of magic file searching: magicPath -> MAGIC env var -> various file system paths (see man file)). On Windows, if no magic files are found after searching, mmmagic will default to the magic file contained in this package (for convenience). 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)
    • MAGIC_COMPRESS - Check inside compressed files
    • MAGIC_DEVICES - Look at the contents of devices
    • MAGIC_MIME_TYPE - Return the MIME type
    • MAGIC_CONTINUE - Return all matches
    • MAGIC_CHECK - Print warnings to stderr
    • MAGIC_PRESERVE_ATIME - Restore access time on exit
    • MAGIC_RAW - Don't translate unprintable chars
    • MAGIC_ERROR - Handle ENOENT etc as real errors
    • 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_COMPRESS - Don't check for compressed files
    • 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.

About

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

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.