Skip to content
Slice a stream via a transform stream
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
README.md
index.js
package.json

README.md

Stream slicer

    npm install stream-slicer

usage

var StreamSlicer = require('stream-slicer');
var fs = require('fs');

var read = fs.createReadStream('data');  // data === '1|2|3|4|5|6';
var write = fs.createWriteStream('data1');

var slicer = new StreamSlicer({ sliceBy: '|', replaceWith: '\n'});

slicer.on('slice', function (data) {
    console.log(data);
});

read.pipe(slicer).pipe(write); 

/*
    data1 ===

    1
    2
    3
    4
    5
    6

*/

also:

var StreamSlicer = require('stream-slicer');
var fs = require('fs');

var read = fs.createReadStream('data');  // data === '1||2|3||4|5||6';
var write = fs.createWriteStream('data1');

var slicer = new StreamSlicer({ sliceBy: '||', replaceWith: '---'});

slicer.on('slice', function (data) {
    console.log(data);
});

read.pipe(slicer).pipe(write); // data1 === '1---2|3---4|5---6'
Something went wrong with that request. Please try again.