Skip to content

Commit

Permalink
chore: some formatting happens...
Browse files Browse the repository at this point in the history
Signed-off-by: Charlike Mike Reagent <opensource@tunnckocore.com>
  • Loading branch information
tunnckoCore committed Jan 28, 2020
1 parent 8c168e6 commit 1bef152
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions example/multipartParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ multipartParser.on('error', (error) => {
});

multipartParser.initWithBoundary(boundary.substring(2)); // todo make better error message when it is forgotten
const shouldWait = !multipartParser.write(buffer);
// const shouldWait = !multipartParser.write(buffer);
multipartParser.end();
// multipartParser.destroy();
// multipartParser.destroy();
2 changes: 1 addition & 1 deletion src/default_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ const defaultOptions = {
hash: false,
multiples: false,
};

exports.defaultOptions = defaultOptions;
2 changes: 1 addition & 1 deletion src/dummy_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DummyParser extends Transform {
super();
this.incomingForm = incomingForm;
}

_flush(callback) {
this.incomingForm.ended = true;
this.incomingForm._maybeEnd();
Expand Down
2 changes: 1 addition & 1 deletion src/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function File(properties) {
this.lastModifiedDate = null;

this._writeStream = null;

for (var key in properties) {
this[key] = properties[key];
}
Expand Down
1 change: 0 additions & 1 deletion src/incoming_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ IncomingForm.prototype.parse = function(req, cb) {
this._parser.end();
});


return this;
};

Expand Down
38 changes: 19 additions & 19 deletions src/multipart_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class MultipartParser extends Transform {
this.boundary = Buffer.from(`\r\n--${str}`);
this.lookbehind = Buffer.alloc(this.boundary.length+8);
this.state = S.START;

this.boundaryChars = {};

for (var i = 0; i < this.boundary.length; i++) {
this.boundaryChars[this.boundary[i]] = true;
}
Expand All @@ -89,7 +89,7 @@ class MultipartParser extends Transform {
bufferLength = buffer.length,
c,
cl,

mark = (name) => {
this[`${name}Mark`] = i;
},
Expand All @@ -107,7 +107,7 @@ class MultipartParser extends Transform {
if (!(markSymbol in this)) {
return;
}

if (!clear) {
callback(name, buffer, this[markSymbol], buffer.length);
this[markSymbol] = 0;
Expand All @@ -116,7 +116,7 @@ class MultipartParser extends Transform {
delete this[markSymbol];
}
};

for (i = 0; i < len; i++) {
c = buffer[i];
switch (state) {
Expand Down Expand Up @@ -148,7 +148,7 @@ class MultipartParser extends Transform {
}
break;
}

if (c != boundary[index+2]) {
index = -2;
}
Expand All @@ -166,12 +166,12 @@ class MultipartParser extends Transform {
state = S.HEADERS_ALMOST_DONE;
break;
}

index++;
if (c == HYPHEN) {
break;
}

if (c == COLON) {
if (index == 1) {
// empty header field
Expand All @@ -181,7 +181,7 @@ class MultipartParser extends Transform {
state = S.HEADER_VALUE_START;
break;
}

cl = lower(c);
if (cl < A || cl > Z) {
return i;
Expand All @@ -191,7 +191,7 @@ class MultipartParser extends Transform {
if (c == SPACE) {
break;
}

mark('headerValue');
state = S.HEADER_VALUE;
case S.HEADER_VALUE:
Expand All @@ -211,7 +211,7 @@ class MultipartParser extends Transform {
if (c != LF) {
return i;
}

callback('headersEnd');
state = S.PART_DATA_START;
break;
Expand All @@ -220,7 +220,7 @@ class MultipartParser extends Transform {
mark('partData');
case S.PART_DATA:
prevIndex = index;

if (index === 0) {
// boyer-moore derrived algorithm to safely skip non-boundary data
i += boundaryEnd;
Expand All @@ -230,7 +230,7 @@ class MultipartParser extends Transform {
i -= boundaryEnd;
c = buffer[i];
}

if (index < boundary.length) {
if (boundary[index] == c) {
if (index === 0) {
Expand Down Expand Up @@ -275,7 +275,7 @@ class MultipartParser extends Transform {
index = 0;
}
}

if (index > 0) {
// when matching a possible boundary, keep a lookbehind reference
// in case it turns out to be a false lead
Expand All @@ -286,31 +286,31 @@ class MultipartParser extends Transform {
callback('partData', lookbehind, 0, prevIndex);
prevIndex = 0;
mark('partData');

// reconsider the current character even so it interrupted the sequence
// it could be the beginning of a new sequence
i--;
}

break;
case S.END:
break;
default:
return i;
}
}

dataCallback('headerField');
dataCallback('headerValue');
dataCallback('partData');

this.index = index;
this.state = state;
this.flags = flags;

return len;
}

explain () {
return `state = ${MultipartParser.stateToString(this.state)}`;
}
Expand Down
1 change: 0 additions & 1 deletion src/octet_parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { PassThrough } = require('stream');


class OctetParser extends PassThrough {}

exports.OctetParser = OctetParser;
1 change: 0 additions & 1 deletion src/querystring_parser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { Transform } = require('stream');
const querystring = require('querystring');


// This is a buffering parser, not quite as nice as the multipart one.
// If I find time I'll rewrite this to be fully streaming as well
class QuerystringParser extends Transform {
Expand Down

0 comments on commit 1bef152

Please sign in to comment.