2 const {PassThrough} = require('stream');
4 module.exports = options => {
5 options = Object.assign({}, options);
7 const {array} = options;
8 let {encoding} = options;
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;