Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var Dissolve = module.exports = function Dissolve(options) {

stream.Transform.call(this, options);

this.offset = 0;
this.jobs = [];
this.vars = Object.create(null);
this.vars_list = [];
Expand Down Expand Up @@ -118,10 +119,16 @@ Dissolve.prototype._exec_buffer = function _exec_buffer(job, offset, length) {
};

Dissolve.prototype._transform = function _transform(input, encoding, done) {
var that = this;
var offset = 0;

this._buffer.append(input);

function moveOffset(value) {
offset += value;
that.offset += value;
}

while (this.jobs.length) {
var job = this.jobs[0];

Expand Down Expand Up @@ -158,19 +165,19 @@ Dissolve.prototype._transform = function _transform(input, encoding, done) {

if (job.type === "buffer") {
this._exec_buffer(job, offset, length);
offset += length;
moveOffset(length);
continue;
}

if (job.type === "string") {
this._exec_string(job, offset, length);
offset += length;
moveOffset(length);
continue;
}

if (job.type === "skip") {
this.jobs.shift();
offset += length;
moveOffset(length);
continue;
}

Expand Down Expand Up @@ -200,7 +207,7 @@ Dissolve.prototype._transform = function _transform(input, encoding, done) {

this.jobs.shift();

offset += length;
moveOffset(length);
}

this._buffer.consume(offset);
Expand Down