UNPKG

streaming

Version:

Transforms and other streaming helpers

22 lines (18 loc) 644 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readToEnd = readToEnd; /** Read a stream to the end, storing all chunks in an array. For example, to read all STDIN: streaming.readToEnd(process.stdin, (err, chunks) => { if (err) throw err; const input = chunks.join(''); console.log('Got input of length: ' + input.length); }); */ function readToEnd(stream, callback) { var chunks = []; return stream .on('error', callback) .on('data', function (chunk) { return chunks.push(chunk); }) .on('end', function () { return callback(null, chunks); }); }