thedesk/app/node_modules/slice-stream
2018-02-18 16:29:06 +09:00
..
examples TheDesk Riina (ver.2) 2018-02-18 16:29:06 +09:00
test TheDesk Riina (ver.2) 2018-02-18 16:29:06 +09:00
.travis.yml TheDesk Riina (ver.2) 2018-02-18 16:29:06 +09:00
LICENSE TheDesk Riina (ver.2) 2018-02-18 16:29:06 +09:00
package.json TheDesk Riina (ver.2) 2018-02-18 16:29:06 +09:00
README.md TheDesk Riina (ver.2) 2018-02-18 16:29:06 +09:00
slicestream.js TheDesk Riina (ver.2) 2018-02-18 16:29:06 +09:00

slice-stream Build Status

Pipe data through a stream until some fixed length is reached, then callback.

Installation

$ npm install slice-stream

Quick Example

End stream once a fixed length has been reached

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'

License

MIT