How to use the stream-mmmagic function in stream-mmmagic

To help you get started, we’ve selected a few stream-mmmagic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github oohnoitz / jii / lib / storage / gridfs.js View on Github external
save(file, readStream, cb) {
    debug('save', file)
    if (file.metadata.secure && (!file.crypto.algorithm || !file.crypto.passphrase)) {
      return cb('You did not provide a valid crypto algorithm and/or passphrase.')
    }

    detectMime(readStream, (err, mime, dataStream) => {
      if (err) {
        return cb(err)
      }

      // set default mime value if libmagic fails
      if (mime === null) {
        mime = { type: 'application/octet-stream' }
      }

      // perform additional lookup when mime type is text/plain
      mime.type = mime.type === 'text/plain'
        ? mimeType.lookup(file.filename) || 'text/plain'
        : mime.type

      // detect if file is blacklisted
      const { blacklist } = this._storageConfig
github oohnoitz / jii / lib / storage / diskfs.js View on Github external
save(file, readStream, cb) {
    debug('save', file)
    if (file.metadata.secure && (!file.crypto.algorithm || !file.crypto.passphrase)) {
      return cb('You did not provide a valid crypto algorithm and/or passphrase.')
    }

    detectMime(readStream, (err, mime, dataStream) => {
      if (err) {
        return cb(err)
      }

      // set default mime value if libmagic fails
      if (mime === null) {
        mime = { type: 'application/octet-stream' }
      }

      // perform additional lookup when mime type is text/plain
      mime.type = mime.type === 'text/plain'
        ? mimeType.lookup(file.filename) || 'text/plain'
        : mime.type

      // detect if file is blacklisted
      const { blacklist } = this._storageConfig

stream-mmmagic

sniff the start of a stream (non-destructively) to detect the file type and encoding

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis

Popular stream-mmmagic functions