Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 7 additions & 16 deletions lib/Dicer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Writable } = require('stream');

inherits = require('util').inherits;
const StreamSearch = require('streamsearch');

const PartStream = require('./PartStream');
Expand Down Expand Up @@ -29,7 +29,6 @@ class Dicer extends Writable {
this._dashes = 0;
this._parts = 0;
this._finished = false;
this._realFinish = false;
this._isPreamble = true;
this._justMatched = false;
this._firstWrite = true;
Expand All @@ -56,7 +55,7 @@ class Dicer extends Writable {
}

emit(ev) {
if (ev !== 'finish' || this._realFinish) {
if (ev !== 'finish') {
Writable.prototype.emit.apply(this, arguments);
return;
}
Expand All @@ -76,16 +75,12 @@ class Dicer extends Writable {
);
this._part.push(null);
process.nextTick(() => {
this._realFinish = true;
this.emit('finish');
this._realFinish = false;
WritableStream.prototype.emit.call(self, 'finish');
});
return;
}

this._realFinish = true;
this.emit('finish');
this._realFinish = false;
WritableStream.prototype.emit.call(self, 'finish');
});
}

Expand Down Expand Up @@ -160,9 +155,7 @@ function onInfo(isMatch, data, start, end) {
this._finished = true;
// No more parts will be added
if (this._parts === 0) {
this._realFinish = true;
this.emit('finish');
this._realFinish = false;
WritableStream.prototype.emit.call(self, 'finish');
}
}
if (this._dashes)
Expand Down Expand Up @@ -190,7 +183,7 @@ function onInfo(isMatch, data, start, end) {
shouldWriteMore = this._part.push(data.slice(start, end));
if (!shouldWriteMore)
this._pause = true;
} else if (!this._isPreamble && this._inHeader) {
} else {
if (buf)
this._hparser.push(buf);
r = this._hparser.push(data.slice(start, end));
Expand All @@ -207,9 +200,7 @@ function onInfo(isMatch, data, start, end) {
this._part.on('end', () => {
if (--this._parts === 0) {
if (this._finished) {
this._realFinish = true;
this.emit('finish');
this._realFinish = false;
WritableStream.prototype.emit.call(self, 'finish');
} else {
unpause(this);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/HeaderParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class HeaderParser extends EventEmitter {
this.ss = new StreamSearch(B_DCRLF, (isMatch, data, start, end) => {
if (data && !this.maxed) {
if (this.nread + (end - start) > MAX_HEADER_SIZE) {
end = (MAX_HEADER_SIZE - this.nread);
end = (MAX_HEADER_SIZE - self.nread) + start;
this.nread = MAX_HEADER_SIZE;
} else {
this.nread += (end - start);
Expand Down