stream-slice
Advanced tools
Comparing version
22
index.js
@@ -23,12 +23,22 @@ | ||
SliceStream.prototype._transform = function(chunk, encoding, done) { | ||
var offset = this._offset + chunk.length; | ||
if (!this._emitUp && offset >= this._start) { | ||
this._offset += chunk.length; | ||
if (!this._emitUp && this._offset >= this._start) { | ||
this._emitUp = true; | ||
this.push(chunk.slice(chunk.length - (offset - this._start), this._end)); | ||
var start = chunk.length - (this._offset - this._start); | ||
if(this._offset > this._end) | ||
{ | ||
var end = chunk.length - (this._offset - this._end); | ||
this._emitDown = true; | ||
this.push(chunk.slice(start, end)); | ||
} | ||
else | ||
{ | ||
this.push(chunk.slice(start, chunk.length)); | ||
} | ||
return done(); | ||
} | ||
if (this._emitUp && !this._emitDown) { | ||
if (offset >= this.end) { | ||
if (this._offset >= this._end) { | ||
this._emitDown = true; | ||
this.push(chunk.slice(chunk.length - (offset - this._end))); | ||
this.push(chunk.slice(0, chunk.length - (this._offset - this._end))); | ||
} else { | ||
@@ -39,3 +49,3 @@ this.push(chunk); | ||
} | ||
done(); | ||
return done(); | ||
} | ||
@@ -42,0 +52,0 @@ |
{ | ||
"name": "stream-slice", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "slice stream like buffer/string", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
3766
7.26%87
12.99%