Sha256: 2aabc4a3368cc1fcf5e8180035c385ae6e3f4a5cb1340ba89106d3bce56e0c08

Contents?: true

Size: 1.72 KB

Versions: 33

Compression:

Stored size: 1.72 KB

Contents

var pump = require('pump')
var inherits = require('inherits')
var Duplexify = require('duplexify')

var toArray = function(args) {
  if (!args.length) return []
  return Array.isArray(args[0]) ? args[0] : Array.prototype.slice.call(args)
}

var define = function(opts) {
  var Pumpify = function() {
    var streams = toArray(arguments)
    if (!(this instanceof Pumpify)) return new Pumpify(streams)
    Duplexify.call(this, null, null, opts)
    if (streams.length) this.setPipeline(streams)
  }

  inherits(Pumpify, Duplexify)

  Pumpify.prototype.setPipeline = function() {
    var streams = toArray(arguments)
    var self = this
    var ended = false
    var w = streams[0]
    var r = streams[streams.length-1]

    r = r.readable ? r : null
    w = w.writable ? w : null

    var onclose = function() {
      streams[0].emit('error', new Error('stream was destroyed'))
    }

    this.on('close', onclose)
    this.on('prefinish', function() {
      if (!ended) self.cork()
    })

    pump(streams, function(err) {
      self.removeListener('close', onclose)
      if (err) return self.destroy(err.message === 'premature close' ? null : err)
      ended = true
      // pump ends after the last stream is not writable *but*
      // pumpify still forwards the readable part so we need to catch errors
      // still, so reenable autoDestroy in this case
      if (self._autoDestroy === false) self._autoDestroy = true
      self.uncork()
    })

    if (this.destroyed) return onclose()
    this.setWritable(w)
    this.setReadable(r)
  }

  return Pumpify
}

module.exports = define({autoDestroy:false, destroy:false})
module.exports.obj = define({autoDestroy: false, destroy:false, objectMode:true, highWaterMark:16})
module.exports.ctor = define

Version data entries

33 entries across 32 versions & 10 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/pumpify/index.js
disco_app-0.18.0 test/dummy/node_modules/pumpify/index.js
disco_app-0.18.2 test/dummy/node_modules/pumpify/index.js
disco_app-0.16.1 test/dummy/node_modules/pumpify/index.js
disco_app-0.15.2 test/dummy/node_modules/pumpify/index.js
disco_app-0.18.4 test/dummy/node_modules/pumpify/index.js
disco_app-0.18.1 test/dummy/node_modules/pumpify/index.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/pumpify/index.js
disco_app-0.14.0 test/dummy/node_modules/pumpify/index.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/pumpify/index.js
tang-0.2.1 spec/tang_app/node_modules/pumpify/index.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/pumpify/index.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/pumpify/index.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/pumpify/index.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/pumpify/index.js
tang-0.2.0 spec/tang_app/node_modules/pumpify/index.js
tang-0.1.0 spec/tang_app/node_modules/pumpify/index.js
tang-0.0.9 spec/tang_app/node_modules/pumpify/index.js
enju_library-0.3.8 spec/dummy/node_modules/pumpify/index.js
ilog-0.4.1 node_modules/pumpify/index.js