Comparing version 0.1.2 to 0.1.3
@@ -12,16 +12,16 @@ var WritableStream = require('readable-stream').Writable, | ||
function Dicer(opts) { | ||
function Dicer(cfg) { | ||
if (!(this instanceof Dicer)) | ||
return new Dicer(opts); | ||
return new Dicer(cfg); | ||
WritableStream.call(this); | ||
if (!opts.headerFirst && typeof opts.boundary !== 'string') | ||
if (!cfg.headerFirst && typeof cfg.boundary !== 'string') | ||
throw new TypeError('Boundary required'); | ||
if (typeof opts.boundary === 'string') | ||
this.setBoundary(opts.boundary); | ||
if (typeof cfg.boundary === 'string') | ||
this.setBoundary(cfg.boundary); | ||
else | ||
this._bparser = undefined; | ||
this._headerFirst = opts.headerFirst; | ||
this._headerFirst = cfg.headerFirst; | ||
@@ -37,3 +37,3 @@ var self = this; | ||
this._hparser = new HeaderParser(); | ||
this._hparser = new HeaderParser(cfg); | ||
this._hparser.on('header', function(header) { | ||
@@ -40,0 +40,0 @@ self._inHeader = false; |
@@ -9,5 +9,8 @@ var EventEmitter = require('events').EventEmitter, | ||
RE_HDR = /^([^:]+):[ \t]?(.+)?$/, | ||
MAX_HEADER_PAIRS = 2000, // from node's http.js | ||
MAX_HEADER_SIZE = 80 * 1024; // from node's http_parser | ||
function HeaderParser() { | ||
function HeaderParser(cfg) { | ||
if (!(this instanceof HeaderParser)) | ||
return new HeaderParser(cfg); | ||
EventEmitter.call(this); | ||
@@ -18,2 +21,6 @@ | ||
this.maxed = false; | ||
this.npairs = 0; | ||
this.maxHeaderPairs = (cfg && typeof cfg.maxHeaderPairs === 'number' | ||
? cfg.maxHeaderPairs | ||
: MAX_HEADER_PAIRS); | ||
this.buffer = ''; | ||
@@ -42,15 +49,2 @@ this.header = {}; | ||
HeaderParser.prototype._finish = function() { | ||
if (this.buffer) | ||
this._parseHeader(); | ||
this.ss.matches = this.ss.maxMatches; | ||
var header = this.header; | ||
this.header = {}; | ||
this.buffer = ''; | ||
this.finished = true; | ||
this.nread = 0; | ||
this.maxed = false; | ||
this.emit('header', header); | ||
}; | ||
HeaderParser.prototype.push = function(data) { | ||
@@ -69,3 +63,19 @@ var r = this.ss.push(data); | ||
HeaderParser.prototype._finish = function() { | ||
if (this.buffer) | ||
this._parseHeader(); | ||
this.ss.matches = this.ss.maxMatches; | ||
var header = this.header; | ||
this.header = {}; | ||
this.buffer = ''; | ||
this.finished = true; | ||
this.nread = this.npairs = 0; | ||
this.maxed = false; | ||
this.emit('header', header); | ||
}; | ||
HeaderParser.prototype._parseHeader = function() { | ||
if (this.npairs === this.maxHeaderPairs) | ||
return; | ||
var lines = this.buffer.split(RE_CRLF), len = lines.length, m, h, | ||
@@ -93,2 +103,4 @@ modded = false; | ||
this.header[h] = ['']; | ||
if (++this.npairs === this.maxHeaderPairs) | ||
break; | ||
} else { | ||
@@ -95,0 +107,0 @@ this.buffer = lines[i]; |
{ "name": "dicer", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"author": "Brian White <mscdex@mscdex.net>", | ||
@@ -4,0 +4,0 @@ "description": "A very fast streaming multipart parser for node.js", |
@@ -111,2 +111,4 @@ | ||
* **maxHeaderPairs** - _integer_ - The maximum number of header key=>value pairs to parse **Default:** 2000 (same as node's http). | ||
* **setBoundary**(< _string_ >boundary) - _(void)_ - Sets the boundary to use for parsing and performs some initialization needed for parsing. You should only need to use this if you set `headerFirst` to true in the constructor and are parsing the boundary from the preamble header. | ||
@@ -113,0 +115,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38101
1042
123