const { PassThrough } = require('stream');
969021
function middleware(doIt, req, res) {
  const originalEnd = res.end;

  return new Promise(resolve => {
    res.end = function end(...args) {
      originalEnd.apply(this, args);
      resolve(0);
    };
    doIt(req, res, () => {
      resolve(1);
    });
  });
}
374577
function depsStream(deps) {
    var s = new stream.PassThrough({ objectMode: true });
    Rx.Node.writeToStream(deps, s);

    return function () {
        return s;
    };
}
781927
function createStream() {
  var firstChunk = true;

  var stream = through(function transform(chunk, encoding, next) {
    if (!firstChunk) return next(null, chunk);

    firstChunk = false;

    var regex = /^(.+?)(\(function\(\)\{)/
      , pattern;

    chunk = chunk.toString().replace(regex, function replacer(match, p1, p2) {
      pattern = p1;
      return p2;
    });

    this.push(prune(pattern) + chunk);
    next();
  });

  stream.label = 'prune-umd';
  return stream;
}
793948
function stream2Promise(stream) {
	return new Promise(function(resolve, reject) {
		stream.on('finish', resolve)
		      //https://github.com/sindresorhus/gulp-size/issues/13
			  .on('end', resolve)
			  .on('error', reject);
	});
}
149951
function compile(inFile, outFile, sourceMap, cb) {
    console.log('Compiling ' + inFile + ' to ' + outFile);
    var outStream = fs.createWriteStream(outFile, 'utf8');
    outStream.on('close', cb);
    browserify({debug: true})
      .require(inFile, { entry: true })
      .bundle()
      .pipe(exorcist(sourceMap))
      .pipe(outStream);
}
1246745
function FileOutputStream(istream, destinationFilename, mode=false){
    // wrap into Promise
    return new Promise(function(resolve, reject){

        // file output stream
        let ostream = null;

        // on complete - chmod
        const onComplete = function(){
            // file mode defined ?
            if (mode){
                // set mode of destination file
                _fs.chmod(destinationFilename, mode, function(err){
                    if (err){
                        reject(err);
                    }else{
                        resolve();
                    }
                });
            }else{
                // finish
                resolve();
            }
        }

        // cleanup
        const onError = function(e){
            // detach finish listener!
            if (ostream){
                ostream.removeListener('finish', onComplete);
            }
            
            // close streams
            if (istream){
                istream.destroy();
            }
            if (ostream){
                ostream.end();
            }

            // throw error
            reject(e);
        }

        // add additional error listener to input stream
        istream.on('error', onError);

        // open write stream
        ostream = _fs.createWriteStream(destinationFilename);
        ostream.on('error', onError);
        ostream.on('finish', onComplete);

        // pipe in to out
        istream.pipe(ostream);
    });
}
858372
function require(names, callback, errback, referer) {
      // in amd, first arg can be a config object... we just ignore
      if (typeof names == 'object' && !(names instanceof Array))
        return require.apply(null, Array.prototype.splice.call(arguments, 1, arguments.length - 1));

      // amd require
      if (typeof names == 'string' && typeof callback == 'function')
        names = [names];
      if (names instanceof Array) {
        var dynamicRequires = [];
        for (var i = 0; i < names.length; i++)
          dynamicRequires.push(loader['import'](names[i], referer));
        Promise.all(dynamicRequires).then(function(modules) {
          if (callback)
            callback.apply(null, modules);
        }, errback);
      }

      // commonjs require
      else if (typeof names == 'string') {
        var defaultJSExtension = loader.defaultJSExtensions && names.substr(names.length - 3, 3) != '.js';
        var normalized = loader.decanonicalize(names, referer);
        if (defaultJSExtension && normalized.substr(normalized.length - 3, 3) == '.js')
          normalized = normalized.substr(0, normalized.length - 3);
        var module = loader.get(normalized);
        if (!module)
          throw new Error('Module not already loaded loading "' + names + '" as ' + normalized + (referer ? ' from "' + referer + '".' : '.'));
        return module.__useDefault ? module['default'] : module;
      }

      else
        throw new TypeError('Invalid require');
    }
631948
function appendStream(streams, s) {
    assert.arrayOfObject(streams, 'streams');
    assert.object(s, 'stream');

    if (s instanceof Stream) {
        streams.push({
            raw: false,
            stream: s
        });
    } else {
        assert.optionalBool(s.raw, 'stream.raw');
        assert.object(s.stream, 'stream.stream');
        streams.push(s);
    }
}
1158600
function(stream, callback) {
                    var content = '';
                    stream.on('data', function(chunk) {
                      content += chunk;
                    });
                    stream.on('end', function() {
                      callback(content);
                    });
                  }
1315938
def promise(*args, &callback)
      parent, headers, flags = *args
      promise = new_stream(parent: parent)
      promise.send(
        type: :push_promise,
        flags: flags,
        stream: parent.id,
        promise_stream: promise.id,
        payload: headers.to_a,
      )

      callback.call(promise)
    end
798502
async function createBlobReadStream(dir, oid) {
  const { object: content } = await git.readObject({ dir, oid });
  const stream = new PassThrough();
  stream.end(content);
  return stream;
}
1364397
function passthrough(devicename, baudrate, initialCommand=null){
    return new Promise(function(resolve, reject){

        // try to open the serial port
        const _device = new _serialport(devicename, {
            baudRate: parseInt(baudrate),
            autoOpen: false
        }); 

        // new length parser
        const parser = _device.pipe(new _lengthParser({length: 1}));

        // handle low-level errors
        _device.on('error', reject);

        // listen on incomming data
        parser.on('data', function(input){
            // passthrough
            process.stdout.write(input.toString('utf8'));
        });

        // open connection
        _device.open(function(err){
            if (err){
                reject(err);
            }else{
                // prepare
                if (process.stdin.isTTY){
                    process.stdin.setRawMode(true);
                }
                
                process.stdin.setEncoding('utf8');

                // initial command set ?
                if (initialCommand !== null){
                    _device.write(initialCommand + '\n');
                }

                // pass-through
                process.stdin.on('data', function(data){
                    // ctrl-c ?
                    if (data == '\u0003'){
                        _device.close(function(e){
                            if (e){
                                reject(e);
                            }else{
                                resolve();
                            }
                        });
                    }else{
                        // passthrough stdin->serial
                        _device.write(data);
                    }
                });
            }
        });
    });
}
992161
function( stream ){
			if( typeof stream == 'string' ){
				//if node.js create a writeable stream with this filename
			} else if( internals.hasProperties(stream,['write','end','writable'] && stream.writable)){
				this.objStream = stream;
			} else {
			}
			this._handleBeginSave();
		}
1095999
function build (stream) {
  return stream
    .pipe(plumber())
    .pipe(tap((file) => {
      log.start('build')
        .action('Building JS file')
        .data(paths.fromJs(file.path))
        .send();
    }))
    .pipe(babel(config))
    .pipe(gulp.dest(paths.get.js.dest))
    .pipe(tap((file) => {
      log.success('build')
        .action('Compiled JS File')
        .data(paths.from(paths.get.js.dest, file.path))
        .send();
    }));
}
417502
function OSMStream(options) {
  if (!(this instanceof OSMStream)) return new OSMStream(options);

  Transform.call(this, options);

  var primaryElements = ['node', 'way', 'relation']; // emit-ables
  var subElementName = ['tag', 'nd', 'member'];

  // size of bytes read from source so far
  this.bytesRead = 0;
  // size of bytes written to stream so far
  this.bytesWritten = 0;

  // initialize parser and its event handlers
  this._parser = new expat.Parser();

  this._parser.on('pipe', (function onParserPipe(src) {
    logger('_parser received pipe from ', src.path || '<unknown pipe>');
  }).bind(this));

  this._parser.on('startElement', (function onParserStartElement(name, attrs) {
    var funcname = ['__parse_', name].join('');
    if ((primaryElements.indexOf(name) > -1 && (OSMStream.prototype[funcname])) ||
      (subElementName.indexOf(name) > -1 && this._currentElement !== null && (OSMStream.prototype[funcname]))) {
      OSMStream.prototype[funcname].call(this, attrs);
    }
  }).bind(this));

  this._parser.on('endElement', (function onParserEndElement(name) {
    if ((primaryElements.indexOf(name) < 0)) return;

    var clone = extend({}, this._currentElement);
    this._currentElement = null;

    var pushData = function pushData(data) {
      if (!data) return;

      if (this.listeners('writeable').length > 0) {
        this.emit('writeable', data, (function onWriteable(data) {
          this.__push(data);
        }).bind(this));
      } else {
        this.__push(data);
      }

    }.bind(this);

    if (this.listeners(name).length > 0) {
      this.emit(name, clone, (function onElement(data) {
        pushData(data);
      }.bind(this)));
    } else {
      pushData(clone);
    }
  }).bind(this));

  this._parser.on('error', (function onParserError(err) {
    this.emit('error', err);
  }).bind(this));

  this._parser.on('end', (function onParserEnd() {
  }).bind(this));

  this.on('pipe', (function onPipe(src) {
    if (src === this._parser) return;
    // attaching stream pipe to parser
    logger('Received pipe from ', src.toString(), ', attaching pipe to _parser');
    src.pipe(this._parser);
    this._parser.pipe(this);
  }).bind(this));

}
997374
function streamHandler(stream) {
    return stream
      .pipe(plumber())
      .pipe(sourcemaps.init({loadMaps: true}))
      .pipe(sourcemaps.write('.', {includeContent: true, sourceRoot: '.'}))
      .pipe(gulp.dest(dest));
  }
1115260
function(viewers, req) {
  var stream = bl();

  req.on('data', function(chunk) {
    stream.append(chunk);
  });

  req.on('end', function() {
    var data = stream.toString('ascii');
    console.log('Dispatching: ' + data);
  })
}