Comparing version 0.0.15 to 0.1.0
@@ -42,3 +42,3 @@ // TODO: | ||
finished = false; | ||
process.nextTick(function() { boy.emit('end'); }); | ||
process.nextTick(function() { boy.emit('finish'); }); | ||
} | ||
@@ -168,3 +168,3 @@ } | ||
file.push(data.slice(0, extralen)); | ||
file.emit('limit'); | ||
file.truncated = true; | ||
part.removeAllListeners('data'); | ||
@@ -209,3 +209,3 @@ } else if (!file.push(data)) | ||
} | ||
boy.emit('field', fieldname, buffer, truncated, false); | ||
boy.emit('field', fieldname, buffer, false, truncated); | ||
--nends; | ||
@@ -238,3 +238,3 @@ checkFinished(); | ||
if (this._nparts === 0) | ||
process.nextTick(function() { self._boy.emit('end'); }); | ||
process.nextTick(function() { self._boy.emit('finish'); }); | ||
}; | ||
@@ -250,2 +250,4 @@ | ||
ReadableStream.call(this, opts); | ||
this.truncated = false; | ||
} | ||
@@ -252,0 +254,0 @@ inherits(FileStream, ReadableStream); |
@@ -112,4 +112,4 @@ var jsencoding = require('../../deps/encoding/encoding'), | ||
undefined, | ||
false, | ||
keyTrunc); | ||
keyTrunc, | ||
false); | ||
} | ||
@@ -162,4 +162,4 @@ | ||
convertVal(this._val, this.charset), | ||
this._valTrunc, | ||
this._keyTrunc); | ||
this._keyTrunc, | ||
this._valTrunc); | ||
this._state = 'key'; | ||
@@ -210,11 +210,11 @@ | ||
undefined, | ||
false, | ||
this._keyTrunc); | ||
this._keyTrunc, | ||
false); | ||
} else if (this._state === 'val') { | ||
this.boy.emit('field', convertVal(this._key, this.charset), | ||
convertVal(this._val, this.charset), | ||
this._valTrunc, | ||
this._keyTrunc); | ||
this._keyTrunc, | ||
this._valTrunc); | ||
} | ||
this.boy.emit('end'); | ||
this.boy.emit('finish'); | ||
}; | ||
@@ -221,0 +221,0 @@ |
{ "name": "busboy", | ||
"version": "0.0.15", | ||
"version": "0.1.0", | ||
"author": "Brian White <mscdex@mscdex.net>", | ||
@@ -4,0 +4,0 @@ "description": "A streaming parser for HTML form data for node.js", |
@@ -45,3 +45,3 @@ Description | ||
}); | ||
busboy.on('end', function() { | ||
busboy.on('finish', function() { | ||
console.log('Done parsing form!'); | ||
@@ -91,5 +91,5 @@ res.writeHead(303, { Connection: 'close', Location: '/' }); | ||
}); | ||
busboy.on('end', function() { | ||
busboy.on('finish', function() { | ||
res.writeHead(200, { 'Connection': 'close' }); | ||
res.end('That's all folks!'); | ||
res.end("That 's all folks!"); | ||
}); | ||
@@ -128,3 +128,3 @@ return req.pipe(busboy); | ||
}); | ||
busboy.on('end', function() { | ||
busboy.on('finish', function() { | ||
console.log('Done parsing form!'); | ||
@@ -173,5 +173,7 @@ res.writeHead(303, { Connection: 'close', Location: '/' }); | ||
* **file**(< _string_ >fieldname, < _ReadableStream_ >stream, < _string_ >filename, < _string_ >transferEncoding, < _string_ >mimeType) - Emitted for each new file form field found. `transferEncoding` contains the 'Content-Transfer-Encoding' value for the file stream. `mimeType` contains the 'Content-Type' value for the file stream. Notice that when no file is attached to the field, (typeof filename === 'undefined'), the stream is 0-length but still requires draining to signal that the event was handled, otherwise the 'end' event will not fire. call stream.resume() to drain the stream. | ||
* **file**(< _string_ >fieldname, < _ReadableStream_ >stream, < _string_ >filename, < _string_ >transferEncoding, < _string_ >mimeType) - Emitted for each new file form field found. `transferEncoding` contains the 'Content-Transfer-Encoding' value for the file stream. `mimeType` contains the 'Content-Type' value for the file stream. | ||
* Note that you should always handle the `stream`, whether you care about the file data or not (e.g. you can simply just do `stream.resume();` if you don't care about the contents), otherwise the 'finish' event will never fire on the Busboy instance. | ||
* `stream` also has a boolean property 'truncated', which indicates if the file stream was truncated because a configured file size limit was reached. It's probably best to check this value at the end of the stream. | ||
* **field**(< _string_ >fieldname, < _string_ >value, < _boolean_ >valueTruncated, < _boolean_ >fieldnameTruncated) - Emitted for each new non-file field found. | ||
* **field**(< _string_ >fieldname, < _string_ >value, < _boolean_ >fieldnameTruncated, < _boolean_ >valueTruncated) - Emitted for each new non-file field found. | ||
@@ -185,5 +187,2 @@ * **partsLimit**() - Emitted when specified `parts` limit has been reached. No more 'file' or 'field' events will be emitted. | ||
**Note:** The `stream` passed in on the 'file' event will also emit a 'limit' event (no arguments) if the `fileSize` limit is reached. If this happens, no more data will be available on the stream. | ||
Busboy methods | ||
@@ -190,0 +189,0 @@ -------------- |
@@ -95,3 +95,3 @@ var Multipart = require('../lib/types/multipart'), | ||
expected: [ | ||
['field', 'file_name_0', 'super', true, false], | ||
['field', 'file_name_0', 'super', false, true], | ||
['file', 'upload_file_0', 13, true, '1k_a.dat', '7bit', 'application/octet-stream'] | ||
@@ -117,14 +117,10 @@ ], | ||
busboy.on('file', function(fieldname, stream, filename, encoding, mimeType) { | ||
var nb = 0, hitLimit = false; | ||
var nb = 0; | ||
stream.on('data', function(d) { | ||
nb += d.length; | ||
}) | ||
.on('limit', function() { | ||
hitLimit = true; | ||
}) | ||
.on('end', function() { | ||
results.push(['file', fieldname, nb, hitLimit, filename, encoding, mimeType]); | ||
}).on('end', function() { | ||
results.push(['file', fieldname, nb, stream.truncated, filename, encoding, mimeType]); | ||
}); | ||
}); | ||
busboy.on('end', function() { | ||
busboy.on('finish', function() { | ||
assert.deepEqual(results.length, | ||
@@ -131,0 +127,0 @@ v.expected.length, |
@@ -85,4 +85,4 @@ var UrlEncoded = require('../lib/types/urlencoded'), | ||
{ source: ['foo=bar&baz=bla'], | ||
expected: [['fo', 'bar', false, true], | ||
['ba', 'bla', false, true]], | ||
expected: [['fo', 'bar', true, false], | ||
['ba', 'bla', true, false]], | ||
what: 'Limits: truncated field name', | ||
@@ -92,4 +92,4 @@ limits: { fieldNameSize: 2 } | ||
{ source: ['foo=bar&baz=bla'], | ||
expected: [['foo', 'ba', true, false], | ||
['baz', 'bl', true, false]], | ||
expected: [['foo', 'ba', false, true], | ||
['baz', 'bl', false, true]], | ||
what: 'Limits: truncated field value', | ||
@@ -141,6 +141,6 @@ limits: { fieldSize: 2 } | ||
var busboy = new EventEmitter(), ue, results = []; | ||
busboy.on('field', function(key, val, valTrunc, keyTrunc) { | ||
results.push([key, val, valTrunc, keyTrunc]); | ||
busboy.on('field', function(key, val, keyTrunc, valTrunc) { | ||
results.push([key, val, keyTrunc, valTrunc]); | ||
}); | ||
busboy.on('end', function() { | ||
busboy.on('finish', function() { | ||
assert.deepEqual(results.length, | ||
@@ -147,0 +147,0 @@ v.expected.length, |
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
664040
5302
211