How to use mississippi - 10 common examples

To help you get started, we’ve selected a few mississippi 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 gulpjs / fs-mkdirp-stream / test / index.js View on Github external
'use strict';

var os = require('os');
var path = require('path');

var fs = require('graceful-fs');
var miss = require('mississippi');
var expect = require('expect');
var rimraf = require('rimraf');

var mkdirpStream = require('../');

var pipe = miss.pipe;
var from = miss.from;
var concat = miss.concat;

describe('mkdirpStream', function() {

  var MASK_MODE = parseInt('7777', 8);
  var isWindows = (os.platform() === 'win32');

  var outputBase = path.join(__dirname, './out-fixtures');
  var outputDirpath = path.join(outputBase, './foo');

  function cleanup(done) {
    this.timeout(20000);

    expect.restoreSpies();

    // Async del to get sort-of-fix for https://github.com/isaacs/rimraf/issues/72
github gulpjs / ordered-read-streams / test / main.js View on Github external
/* global it, describe */

var expect = require('expect');

var miss = require('mississippi');

var OrderedStreams = require('..');

var to = miss.to;
var from = miss.from;
var pipe = miss.pipe;
var concat = miss.concat;

function fromOnce(fn) {
  var called = false;
  return from.obj(function(size, next) {
    if (called) {
      return next(null, null);
    }
    called = true;
    fn.apply(this, arguments);
  });
}

describe('ordered-read-streams', function () {
github anandthakker / doiuse.com / index.js View on Github external
var server = http.createServer(function (req, res) {
  var ip = req.headers['x-forwarded-for'] ||
     req.connection.remoteAddress ||
     req.socket.remoteAddress ||
     req.connection.socket.remoteAddress

  // POST /
  // arguments (either query string or POST body) should have either `url` xor
  // `css` property, and optional `browsers`.
  // response is {args: {given args}, usages: [usages of queried features], count:{feature:count}}
  if (req.method !== 'POST') {
    console.log([Date.now(), req.method, req.url, ip].join('\t'))
  }

  if (req.method === 'POST') {
    pipe(
      req,
      limit(1e6, function () { req.connection.destroy() }),
      concat(function (args) {
        console.log([Date.now(), req.method, req.url, ip, args.length + ' B'].join('\t'))

        try {
          args = JSON.parse(args)
          cssFeatures(args, res)
        } catch (e) {
          debug('Error parsing request ', e.toString(), args)
          res.statusCode = 400
          res.end(JSON.stringify({
            error: e.toString(),
            statusCode: 400
          }))
        }
github anandthakker / doiuse.com / index.js View on Github external
req.socket.remoteAddress ||
     req.connection.socket.remoteAddress

  // POST /
  // arguments (either query string or POST body) should have either `url` xor
  // `css` property, and optional `browsers`.
  // response is {args: {given args}, usages: [usages of queried features], count:{feature:count}}
  if (req.method !== 'POST') {
    console.log([Date.now(), req.method, req.url, ip].join('\t'))
  }

  if (req.method === 'POST') {
    pipe(
      req,
      limit(1e6, function () { req.connection.destroy() }),
      concat(function (args) {
        console.log([Date.now(), req.method, req.url, ip, args.length + ' B'].join('\t'))

        try {
          args = JSON.parse(args)
          cssFeatures(args, res)
        } catch (e) {
          debug('Error parsing request ', e.toString(), args)
          res.statusCode = 400
          res.end(JSON.stringify({
            error: e.toString(),
            statusCode: 400
          }))
        }
      }),
      function (err) {
        if (err) { console.error(err) }
github graalvm / graaljs / graal-nodejs / deps / npm / node_modules / pacote / lib / fetchers / file.js View on Github external
tarball (spec, opts) {
    const src = spec._resolved || spec.fetchSpec
    const stream = through()
    statAsync(src).then(stat => {
      if (spec._resolved) { stream.emit('manifest', spec) }
      if (stat.size <= MAX_BULK_SIZE) {
        // YAY LET'S DO THING IN BULK
        return readFileAsync(src).then(data => {
          if (opts.cache) {
            return cacache.put(
              opts.cache, `pacote:tarball:file:${src}`, data, {
                integrity: opts.integrity
              }
            ).then(integrity => ({ data, integrity }))
          } else {
            return { data }
          }
        }).then(info => {
          if (info.integrity) { stream.emit('integrity', info.integrity) }
github graalvm / graaljs / deps / npm / lib / search / all-package-metadata.js View on Github external
let updatedWritten = false
  const inStream = ms.pipeline.obj(
    ms.through.obj((pkg, enc, cb) => {
      if (!updatedWritten && typeof pkg === 'number') {
        // This is the `_updated` value getting sent through.
        updatedWritten = true
        return cb(null, ['_updated', pkg])
      } else if (typeof pkg !== 'object') {
        this.emit('error', new Error('invalid value written to input stream'))
      } else {
        // The [key, val] format is expected by `jsonstream` for object writing
        cb(null, [pkg.name, pkg])
      }
    }),
    JSONStream.stringifyObject('{', ',', '}'),
    ms.through((chunk, enc, cb) => {
      // This tees off the buffer data to `outStream`, and then continues
      // the pipeline as usual
      outStream.write(chunk, enc, () => cb(null, chunk))
    }),
    // And finally, we write to the cache file.
    writer
  )
  inStream.write(latest)
  return inStream
}
github npm / npme-installer / lib / download-tar.js View on Github external
req.on('response', function (res) {
      responded = true
      if (res.statusCode !== 200) {
        var e = new Error()
        e.statusCode = res.statusCode
        return cb(e)
      }

      mis.pipe(res, mis.through(function (chunk, enc, cb) {
        hash.update(chunk)
        cb(false, chunk)
      }), fs.createWriteStream(tmpname), function (err) {
        if (err) {
          console.error('failed downloading ' + tarUrl + ' err = ' + err.message)
          return cb(err)
        }

        var resultShasum = hash.digest().toString('hex')

        if (resultShasum !== shasum) {
          return cb(new Error('shasum mismatch got: ' + resultShasum + ' need ' + shasum))
        }

        fs.rename(tmpname, targetName, function (err) {
          // yay! all done.
github npm / pacote / lib / registry / request.js View on Github external
function registryStream (key, uri, registry, meta, opts) {
  var stream = through()
  client(opts).get(uri, {
    etag: meta && meta.etag,
    lastModified: meta && meta.lastModified,
    follow: opts.follow,
    auth: opts.auth && opts.auth[registryKey(registry)],
    timeout: opts.timeout,
    streaming: true
  }, function (err, res) {
    if (err) { return stream.emit('error', err) }
    var decoder = res.headers['content-encoding'] === 'gzip'
    ? gunzip()
    : through()
    if (res.statusCode === 304) {
      opts.log.silly('registry.get', 'cached data valid')
      res.on('data', function () {}) // Just drain it
      stream.emit('cached')
github npm / pacote / lib / registry / request.js View on Github external
}, function (err, res) {
    if (err) { return stream.emit('error', err) }
    var decoder = res.headers['content-encoding'] === 'gzip'
    ? gunzip()
    : through()
    if (res.statusCode === 304) {
      opts.log.silly('registry.get', 'cached data valid')
      res.on('data', function () {}) // Just drain it
      stream.emit('cached')
      stream.unpipe()
      stream.end()
    } else if (opts.cache) {
      opts.log.silly('registry.get', 'request successful. streaming data to cache')
      var localopt = Object.create(opts)
      localopt.metadata = {
        etag: res.headers['etag'],
        lastModified: res.headers['last-modified'],
        cacheControl: res.headers['cache-conrol'],
        time: +(new Date())
      }
      var cacheStream = cache.put.stream(opts.cache, key, localopt)
github MetaMask / zero-client / frame.js View on Github external
var serialiedTx = '0x'+tx.serialize().toString('hex')
      cb(null, serialiedTx)
    },
    // msg signing
    // approveMessage: addUnconfirmedMsg,
    // signMessage: idStore.signMessage.bind(idStore),
  })

  provider.on('block', function(block){
    console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex'))
  })

  var connectionStream = new ParentStream()
  // setup connectionStream multiplexing 
  var multiStream = ObjectMultiplex()
  Streams.pipe(connectionStream, multiStream, connectionStream, function(err){
    console.warn('MetamaskIframe - lost connection to Dapp')
    if (err) throw err
  })

  var providerStream = multiStream.createStream('provider')
  handleRequestsFromStream(providerStream, provider, logger)

  function logger(err, request, response){
    if (err) return console.error(err.stack)
    if (!request.isMetamaskInternal) {
      console.log('MetaMaskIframe - RPC complete:', request, '->', response)
      if (response.error) console.error('Error in RPC response:\n'+response.error.message)
    }
  }

}