split
Advanced tools
Comparing version 0.2.6 to 0.2.7
12
index.js
@@ -9,4 +9,4 @@ //filter will reemit the data if cb(err,pass) pass is truthy | ||
var through = require('through') | ||
var Decoder = require('string_decoder').StringDecoder | ||
module.exports = split | ||
@@ -17,2 +17,3 @@ | ||
function split (matcher, mapper) { | ||
var decoder = new Decoder() | ||
var soFar = '' | ||
@@ -39,3 +40,3 @@ if('function' === typeof matcher) | ||
return through(function (buffer) { | ||
function next (stream, buffer) { | ||
var pieces = (soFar + buffer).split(matcher) | ||
@@ -46,6 +47,11 @@ soFar = pieces.pop() | ||
var piece = pieces[i] | ||
emit(this, piece) | ||
emit(stream, piece) | ||
} | ||
} | ||
return through(function (b) { | ||
next(this, decoder.write(b)) | ||
}, | ||
function () { | ||
next(this, decoder.end()) | ||
if(soFar != null) | ||
@@ -52,0 +58,0 @@ emit(this, soFar) |
{ | ||
"name": "split", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "split a Text Stream into a Line Stream", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/dominictarr/split", |
9018
10
203