Limit the size of a stream
$ npm install --save limit-size-stream
const fs = require('fs');
const getStream = require('get-stream');
const limitSizeStream = require('limit-size-stream');
const stream = fs.createReadStream('unicorn.txt');
getStream(limitStream(stream, 5)).then(str => {
console.log(str);
//=> 'unico'
});
Type: Stream
Stream to limit.
Type: number
Maximum length of the returned buffer or string.
Type: Stream
Stream to limit.
Type: number
Maximum number of items to return.
MIT © Kevin Martensson