Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mmmagic

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mmmagic

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

  • 0.5.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
91K
decreased by-1.54%
Maintainers
1
Weekly downloads
 
Created

What is mmmagic?

The mmmagic npm package is a Node.js library used for detecting the MIME type and encoding of files. It is a binding to the libmagic library, which is used to identify file types based on their content rather than their file extension.

What are mmmagic's main functionalities?

Detect MIME type of a file

This feature allows you to detect the MIME type of a file. The code sample demonstrates how to use mmmagic to read a file and determine its MIME type, which is useful for handling files based on their content type.

const fs = require('fs');
const mmm = require('mmmagic'), Magic = mmm.Magic;

const magic = new Magic(mmm.MAGIC_MIME_TYPE);
magic.detectFile('path/to/file', function(err, result) {
  if (err) throw err;
  console.log(result); // e.g., 'image/jpeg'
});

Detect MIME encoding of a file

This feature allows you to detect the MIME encoding of a file. The code sample shows how to use mmmagic to determine the encoding of a file, which can be important for processing files correctly.

const fs = require('fs');
const mmm = require('mmmagic'), Magic = mmm.Magic;

const magic = new Magic(mmm.MAGIC_MIME_ENCODING);
magic.detectFile('path/to/file', function(err, result) {
  if (err) throw err;
  console.log(result); // e.g., 'binary'
});

Detect MIME type and encoding of a file

This feature allows you to detect both the MIME type and encoding of a file simultaneously. The code sample demonstrates how to use mmmagic to get both pieces of information in one call, which can be efficient for applications that need both details.

const fs = require('fs');
const mmm = require('mmmagic'), Magic = mmm.Magic;

const magic = new Magic(mmm.MAGIC_MIME);
magic.detectFile('path/to/file', function(err, result) {
  if (err) throw err;
  console.log(result); // e.g., 'image/jpeg; charset=binary'
});

Other packages similar to mmmagic

Keywords

FAQs

Package last updated on 30 Apr 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc