Skip to content

oropesa/oro-mimetype

Repository files navigation

Oro Mimetype

Class OroMimetype is a wrapper of mmmagic to simplify their use.

mmmagic is a module for node.js that check the file mimetype by their content (not the extension).

npm install oro-mimetype

Examples:

const OMimetype = require( 'oro-mimetype' );

const response = await OMimeType.GetFromFilepath( 'image.png' );
// { status: true, filepath: 'image.png', mimetype: 'image/png' }

const response2 = await OMimeType.GetFromFilepath( 'file.pdf' );
// { status: true, filepath: 'file.pdf', mimetype: 'application/pdf' }

const response3 = await OMimeType.GetFromFilepath( 'file-not-exist.pdf' );
// { 
//   status: false, 
//   filepath: 'file-not-exist.pdf', 
//   msg: "Error: File not exists: 'file-not-exist.pdf'"
// }

const isImage = await OMimeType.IsImage( 'image.png' );
// { status: true, filepath: 'image.png', mimetype: 'image/png' }

const isImage2 = await OMimeType.IsImage( 'file.pdf' );
// { 
//   status: false, 
//   filepath: 'file.pdf', 
//   mimetype: 'application/pdf', 
//   failed: 'image', 
//   msg: "Error: File is not image: 'file.pdf'" 
// }

Methods

// TODO pending to be written 

About

Class OroMimetype is a wrapper of mmmagic to work as promises async/await.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published