2 const PassThrough = require('stream').PassThrough;
4 module.exports = opts => {
5 opts = Object.assign({}, opts);
7 const array = opts.array;
8 let encoding = opts.encoding;
9 const buffer = encoding === 'buffer';
10 let objectMode = false;
13 objectMode = !(encoding || buffer);
15 encoding = encoding || 'utf8';
24 const stream = new PassThrough({objectMode});
27 stream.setEncoding(encoding);
30 stream.on('data', chunk => {
40 stream.getBufferedValue = () => {
45 return buffer ? Buffer.concat(ret, len) : ret.join('');
48 stream.getBufferedLength = () => len;