sepstream
v0.2.5
Published
A stream separating utility
Downloads
4
Readme
sepstream
A stream separating utility for Node.js.
Installation
$ npm install sepstream
Usage
var fs = require('fs');
var sepstream = require('sepstream');
fs.createReadStream('/path/to/file1')
.pipe(sepstream(function(data) {
// data comes for every line.
console.log(data.toString());
}))
pipe
var fs = require('fs');
var sepstream = require('sepstream');
fs.createReadStream('/path/to/file1')
.pipe(sepstream(function(data) {
var str = data.toString(); // data comes for every line.
str = str.replace(/abcd/, 'efgh'); // modify str
return new Buffer(str); // send to next pipe
}))
.pipe(fs.createWriteStream('/path/to/file2'));
set separator
var fs = require('fs');
var sepstream = require('sepstream');
fs.createReadStream('/path/to/file1')
.pipe(sepstream(function(data) {
console.log(data.toString());
}, {
sep: '\r\n' // set separator. default: '\n'
}))
set binary separator
var fs = require('fs');
var sepstream = require('sepstream');
fs.createReadStream('/path/to/file1')
.pipe(sepstream(function(data) {
console.log(data);
}, {
sep: [0x32, 0x33, 0x34]
}))
Error handling
var fs = require('fs');
var sepstream = require('sepstream');
fs.createReadStream('/path/to/file1')
.pipe(sepstream(function(data) {
throw new Error('error1');
}))
.on('error', function (err) {
console.log(err.message); // error1
})
License
The MIT License