function wrapResponse(res) { var passThrough = new PassThrough(); passThrough.statusCode = res.statusCode; passThrough.rawHeaderNames = res.rawHeaderNames; passThrough.headers = lowerCaseify(res.headers); passThrough.headers.server = config.name; res.body != null && passThrough.push(Buffer.isBuffer(res.body) ? res.body : String(res.body)); passThrough.push(null); return passThrough; }
function chunkInvalid(state, chunk) { var er; if (!Stream._isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) { er = new errors.TypeError('ERR_INVALID_ARG_TYPE', 'chunk', 'string/Buffer/Uint8Array'); } return er; }
function Readable(options) { if (!(this instanceof Readable)) return new Readable(options); this._readableState = new ReadableState(options, this); // legacy this.readable = true; if (options) { if (typeof options.read === 'function') this._read = options.read; if (typeof options.destroy === 'function') this._destroy = options.destroy; } Stream.call(this); }
function doTask(date) { const env = {DATE: date} console.log('DATE=', date) const p1 = exec('node reduce.js', {env: env}, (err) => { assert.ifError(err) const p2 = exec('indexer -c sphinx.conf hash_delta --rotate', {env: env}, (err) => { assert.ifError(err) const p3 = exec('indexer -c sphinx.conf --merge hash hash_delta --rotate', (err) => { assert.ifError(err) console.log(new Date(), date, 'task done') }) p3.stdout.pipe(process.stdout) }) p2.stdout.pipe(process.stdout) }) p1.stdout.pipe(process.stdout) }
function getDecoder(obj) { return function(socket, callback) { var encoding = obj._originEncoding; var decoder; if (obj._needGunzip || socket || encoding !== obj.headers['content-encoding']) { obj._needGunzip = true; decoder = encoding && util.getUnzipStream(encoding); } var handleError = function(err) { obj.emit('error', err); }; decoder && decoder.on('error', handleError); if (socket) { delete obj.headers['content-length']; var enTrans = getEncodeTransform(); var deTrans = getDecodeTransform(); enTrans.pipe(socket).pipe(deTrans); enTrans.on('error', handleError); deTrans.on('error', handleError); if (decoder) { decoder.pipe(enTrans); } else { decoder = enTrans; } socket = deTrans; } callback(decoder, socket); }; }
!state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) { chunk = Stream._uint8ArrayToBuffer(chunk);
stream.end(); } else { res.end();
if (!done) { done = true; decoder.emit('error', err); encoder.emit('error', err); encoder.once('finish', function() { done = true; }); socket.on('close', function() { done = true; decoder.emit('close'); encoder.emit('close'); }); decoder.destroy = encoder.destroy = handleError; decoder.on('error', handleError); encoder.on('error', handleError); ADDITIONAL_FIELDS.forEach(function(key) { decoder[key] = req[key]; }); socket.pipe(decoder); encoder.pipe(socket); httpServer.emit('request', decoder, encoder); });
var isDuplex = stream instanceof Stream.Duplex;
setEncoding(enc) { return this._reader.setEncoding(enc); }
write(chunk, enc, cb) { return this._writer.write(chunk, enc, cb); }
unpipe(dest) { return this._reader.unpipe(dest) || this.kill(); }
pipe(dest, opts) { return this._reader.pipe(dest, opts); }
read(size) { return this._reader.read(size); }