|
|
há 8 anos atrás | |
|---|---|---|
| .. | ||
| examples | há 8 anos atrás | |
| test | há 8 anos atrás | |
| .travis.yml | há 8 anos atrás | |
| LICENSE | há 8 anos atrás | |
| README.md | há 8 anos atrás | |
| package.json | há 8 anos atrás | |
| slicestream.js | há 8 anos atrás | |

Pipe data through a stream until some fixed length is reached, then callback.
$ npm install slice-stream
var SliceStream = require('../');
var streamBuffers = require("stream-buffers");
var ss = new SliceStream({ length: 5}, function (buf, sliceEnd, extra) {
if (!sliceEnd) {
return this.push(buf);
}
this.push(buf);
return this.push(null); //signal end of data
});
var sourceStream = new streamBuffers.ReadableStreamBuffer();
sourceStream.put("Hello World");
var writableStream = new streamBuffers.WritableStreamBuffer();
sourceStream
.pipe(ss)
.pipe(writableStream)
.once('close', function () {
var str = writableStream.getContentsAsString('utf8');
console.log('First 5 bytes piped:', "'" + str + "'");
sourceStream.destroy();
});
//Output
//Piped data before pattern occurs: 'Hello'
MIT