Collect a readable stream's data into buffer. Support max size limit.
npm i stream-to-buf
const streamTobuffer = require('stream-to-buf');
const stream = fs.createReadStream(path.join(__dirname, 'fixtures/file'));
streamToBuffer(stream, { maxSize: '10kb' }).then(onBuffer, onError);
maxSize
: If stream's emitted buffer exceedmaxSize
, it will throw an error.(but it will still consume the stream before resolve).