Skip to content

Commit bf10f2f

Browse files
committed
Dummy parser is a stream
1 parent dd4a9d5 commit bf10f2f

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

example/multipartParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ multipartParser.on('error', (error) => {
2424
multipartParser.initWithBoundary(boundary.substring(2)); // todo make better error message when it is forgotten
2525
const shouldWait = !multipartParser.write(buffer);
2626
multipartParser.end();
27-
// multipartParser.destroy();
27+
// multipartParser.destroy();

lib/dummy_parser.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { Transform } = require('stream');
2+
3+
4+
class DummyParser extends Transform {
5+
constructor(incomingForm) {
6+
super();
7+
this.incomingForm = incomingForm;
8+
}
9+
10+
_flush(callback) {
11+
this.incomingForm.ended = true;
12+
this.incomingForm._maybeEnd();
13+
callback();
14+
}
15+
}
16+
17+
18+
exports.DummyParser = DummyParser;

lib/incoming_form.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var util = require('util'),
66
path = require('path'),
77
File = require('./file'),
88
defaultOptions = require('./default_options').defaultOptions,
9+
DummyParser = require('./dummy_parser').DummyParser,
910
MultipartParser = require('./multipart_parser').MultipartParser,
1011
QuerystringParser = require('./querystring_parser').QuerystringParser,
1112
OctetParser = require('./octet_parser').OctetParser,
@@ -145,6 +146,7 @@ IncomingForm.prototype.parse = function(req, cb) {
145146
this._parser.end();
146147
});
147148

149+
console.log(this._parser)
148150
this._parser.once('error', (error) => {
149151
this._error(error);
150152
});
@@ -252,19 +254,10 @@ IncomingForm.prototype.handlePart = function(part) {
252254
});
253255
};
254256

255-
function dummyParser(incomingForm) {
256-
return {
257-
end: function () {
258-
incomingForm.ended = true;
259-
incomingForm._maybeEnd();
260-
return null;
261-
}
262-
};
263-
}
264257

265258
IncomingForm.prototype._parseContentType = function() {
266259
if (this.bytesExpected === 0) {
267-
this._parser = dummyParser(this);
260+
this._parser = new DummyParser(this);
268261
return;
269262
}
270263

0 commit comments

Comments
 (0)