Comparing version 0.0.9 to 0.0.10
@@ -19,5 +19,5 @@ var fs = require('fs'), | ||
this.opts = opts; | ||
if (opts.headers && typeof opts.headers['content-type'] === 'string') | ||
this.parseHeaders(opts.headers); | ||
this.limits = opts.limits; | ||
this.once('finish', function() { | ||
@@ -44,3 +44,12 @@ self._parser && self._parser.end(); | ||
if (matched) { | ||
this._parser = new type(this, this.limits, headers, parsed); | ||
var cfg = { | ||
limits: this.opts.limits, | ||
headers: headers, | ||
parsedConType: parsed | ||
}; | ||
if (this.opts.highWaterMark) | ||
cfg.highWaterMark = this.opts.highWaterMark; | ||
if (this.opts.fileHwm) | ||
cfg.fileHwm = this.opts.fileHwm; | ||
this._parser = new type(this, cfg); | ||
return; | ||
@@ -53,4 +62,3 @@ } | ||
Busboy.prototype._write = function(chunk, encoding, cb) { | ||
this._parser.write(chunk); | ||
cb(); | ||
this._parser.write(chunk, cb); | ||
}; | ||
@@ -57,0 +65,0 @@ |
@@ -22,4 +22,11 @@ // TODO: | ||
Multipart.detect = /^multipart\//i; | ||
function Multipart(boy, limits, headers, parsedConType) { | ||
var boundary, i, len; | ||
function Multipart(boy, cfg) { | ||
var boundary, i, len, self = this, | ||
limits = cfg.limits, | ||
headers = cfg.headers, | ||
parsedConType = cfg.parsedConType, | ||
fileopts = typeof cfg.fileHwm === 'number' | ||
? { highWaterMark: cfg.fileHwm } | ||
: {}; | ||
for (i = 0, len = parsedConType.length; i < len; ++i) { | ||
@@ -32,2 +39,9 @@ if (RE_BOUNDARY.test(parsedConType[i][0])) { | ||
function checkFinished() { | ||
if (nends === 0 && finished) { | ||
finished = false; | ||
process.nextTick(function() { boy.emit('end'); }); | ||
} | ||
} | ||
if (!boundary) | ||
@@ -42,13 +56,31 @@ throw new Error('Multipart: Boundary not found'); | ||
var nfiles = 0, nfields = 0, nparts = 0; | ||
var nfiles = 0, nfields = 0, nparts = 0, nends = 0, | ||
finished = false; | ||
this._boy = boy; | ||
this.parser = new Dicer({ | ||
this._needDrain = false; | ||
this._pause = false; | ||
this._cb = undefined; | ||
var parserCfg = { | ||
boundary: boundary, | ||
maxHeaderPairs: (limits && limits.headerPairs) | ||
}; | ||
if (fileopts.highWaterMark) | ||
parserCfg.partHwm = fileopts.highWaterMark; | ||
if (cfg.highWaterMark) | ||
parserCfg.highWaterMark = cfg.highWaterMark | ||
this.parser = new Dicer(parserCfg); | ||
this.parser.on('drain', function() { | ||
self._needDrain = false; | ||
if (self._cb && !self._pause) { | ||
var cb = self._cb; | ||
self._cb = undefined; | ||
cb(); | ||
} | ||
}); | ||
this.parser.on('part', function(part) { | ||
this.parser.on('part', function onPart(part) { | ||
if (++nparts > partsLimit) { | ||
this.parser.removeAllListeners('part'); | ||
self.parser.removeListener('part', onPart); | ||
self.parser.on('part', skipParts); | ||
return; | ||
@@ -68,3 +100,5 @@ } | ||
} | ||
} | ||
} else | ||
contype = 'text/plain'; | ||
if (charset === undefined) | ||
@@ -98,3 +132,18 @@ charset = 'iso-8859-1'; | ||
++nfiles; | ||
var file = new FileStream(); | ||
++nends; | ||
var file = new FileStream(fileopts); | ||
file.on('end', function() { | ||
--nends; | ||
checkFinished(); | ||
}); | ||
file._read = function(n) { | ||
if (!self._pause) | ||
return; | ||
self._pause = false; | ||
if (self._cb && !self._needDrain) { | ||
var cb = self._cb; | ||
self._cb = undefined; | ||
cb(); | ||
} | ||
}; | ||
boy.emit('file', fieldname, file, filename, encoding, contype); | ||
@@ -107,4 +156,4 @@ | ||
part.removeAllListeners('data'); | ||
} else | ||
file.push(data); | ||
} else if (!file.push(data)) | ||
self._pause = true; | ||
}; | ||
@@ -121,2 +170,3 @@ | ||
++nfields; | ||
++nends; | ||
var buffer = '', truncated = false; | ||
@@ -141,2 +191,4 @@ | ||
boy.emit('field', fieldname, buffer, truncated, false); | ||
--nends; | ||
checkFinished(); | ||
}; | ||
@@ -149,8 +201,14 @@ } | ||
this.parser.on('end', function() { | ||
boy.emit('end'); | ||
finished = true; | ||
}); | ||
} | ||
Multipart.prototype.write = function(data) { | ||
this.parser.write(data); | ||
Multipart.prototype.write = function(chunk, cb) { | ||
var r; | ||
if ((r = this.parser.write(chunk)) && !this._pause) | ||
cb(); | ||
else { | ||
this._needDrain = !r; | ||
this._cb = cb; | ||
} | ||
}; | ||
@@ -160,6 +218,10 @@ | ||
function FileStream() { | ||
function skipParts(part) { | ||
part.resume(); | ||
} | ||
function FileStream(opts) { | ||
if (!(this instanceof FileStream)) | ||
return new FileStream(); | ||
ReadableStream.call(this); | ||
return new FileStream(opts); | ||
ReadableStream.call(this, opts); | ||
} | ||
@@ -166,0 +228,0 @@ inherits(FileStream, ReadableStream); |
@@ -7,3 +7,6 @@ var jsencoding = require('../../deps/encoding/encoding'), | ||
UrlEncoded.detect = /^application\/x-www-form-urlencoded/i; | ||
function UrlEncoded(boy, limits, headers, parsedConType) { | ||
function UrlEncoded(boy, cfg) { | ||
var limits = cfg.limits, | ||
headers = cfg.headers, | ||
parsedConType = cfg.parsedConType; | ||
this.boy = boy; | ||
@@ -46,5 +49,5 @@ | ||
UrlEncoded.prototype.write = function(data) { | ||
UrlEncoded.prototype.write = function(data, cb) { | ||
if (this._fields === this.fieldsLimit) | ||
return; | ||
return cb(); | ||
@@ -112,3 +115,3 @@ var idxeq, idxamp, i, p = 0, len = data.length; | ||
if (this._fields === this.fieldsLimit) | ||
return; | ||
return cb(); | ||
} else if (this._hitLimit) { | ||
@@ -169,3 +172,3 @@ // we may not have hit the actual limit if there are encoded bytes... | ||
if (this._fields === this.fieldsLimit) | ||
return; | ||
return cb(); | ||
} else if (this._hitLimit) { | ||
@@ -197,2 +200,3 @@ // we may not have hit the actual limit if there are encoded bytes... | ||
} | ||
cb(); | ||
}; | ||
@@ -199,0 +203,0 @@ |
{ "name": "busboy", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"author": "Brian White <mscdex@mscdex.net>", | ||
@@ -7,3 +7,3 @@ "description": "A streaming parser for HTML form data for node.js", | ||
"dependencies": { | ||
"dicer": "0.1.4", | ||
"dicer": "0.1.5", | ||
"readable-stream": "1.1.x" | ||
@@ -10,0 +10,0 @@ }, |
@@ -204,4 +204,6 @@ Description | ||
* **highWaterMark** - _integer_ - highWaterMark from WritableStream (Default: WritableStream default). | ||
* **highWaterMark** - _integer_ - highWaterMark to use for this Busboy instance (Default: WritableStream default). | ||
* **fileHwm** - _integer_ - highWaterMark to use for file streams (Default: ReadableStream default). | ||
* **limits** - _object_ - Various limits on incoming data. Valid properties are: | ||
@@ -208,0 +210,0 @@ |
@@ -9,2 +9,3 @@ var Multipart = require('../lib/types/multipart'), | ||
var EMPTY_FN = function() {}; | ||
@@ -48,8 +49,10 @@ var t = 0, | ||
function next() { | ||
var v = tests[t++]; | ||
if (t === tests.length) | ||
return; | ||
var v = tests[t]; | ||
var busboy = new EventEmitter(), | ||
mp, | ||
results = [], | ||
ends = 0; | ||
results = []; | ||
@@ -72,21 +75,2 @@ busboy.on('field', function(key, val, valTrunc, keyTrunc) { | ||
busboy.on('end', function() { | ||
++ends; | ||
}); | ||
mp = new Multipart(busboy, | ||
v.limits, | ||
null, | ||
parseParams('multipart/form-data; boundary=' + v.boundary)); | ||
v.source.forEach(function(s) { | ||
mp.write(new Buffer(s, 'utf8')); | ||
}); | ||
mp.end(); | ||
setImmediate(function() { | ||
assert.equal(ends, | ||
1, | ||
makeMsg(v.what, "Incorrect 'end' count: " | ||
+ ends | ||
+ " instead of 1")); | ||
assert.deepEqual(results.length, | ||
@@ -106,5 +90,16 @@ v.expected.length, | ||
}); | ||
if (t < tests.length) | ||
next(); | ||
++t; | ||
next(); | ||
}); | ||
var cfg = { | ||
limits: v.limits, | ||
headers: null, | ||
parsedConType: parseParams('multipart/form-data; boundary=' + v.boundary) | ||
}; | ||
mp = new Multipart(busboy, cfg); | ||
v.source.forEach(function(s) { | ||
mp.write(new Buffer(s, 'utf8'), EMPTY_FN); | ||
}); | ||
mp.end(); | ||
} | ||
@@ -115,2 +110,7 @@ next(); | ||
return '[' + group + what + ']: ' + msg; | ||
} | ||
} | ||
process.on('exit', function() { | ||
assert(t === tests.length, | ||
makeMsg('Only ran ' + t + '/' + tests.length + ' tests')); | ||
}); |
@@ -9,2 +9,4 @@ var UrlEncoded = require('../lib/types/urlencoded'), | ||
var EMPTY_FN = function() {}; | ||
var group = path.basename(__filename, '.js') + '/'; | ||
@@ -133,6 +135,11 @@ | ||
}); | ||
ue = new UrlEncoded(busboy, v.limits, null, parsedConType); | ||
var cfg = { | ||
limits: v.limits, | ||
headers: null, | ||
parsedConType: parsedConType | ||
}; | ||
ue = new UrlEncoded(busboy, cfg); | ||
v.source.forEach(function(s) { | ||
ue.write(new Buffer(s, 'utf8')); | ||
ue.write(new Buffer(s, 'utf8'), EMPTY_FN); | ||
}); | ||
@@ -139,0 +146,0 @@ ue.end(); |
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
657111
5112
223
+ Addeddicer@0.1.5(transitive)
- Removeddicer@0.1.4(transitive)
Updateddicer@0.1.5