Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

busboy

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

busboy - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

8

lib/main.js
var fs = require('fs'),
EventEmitter = require('events').EventEmitter,
WritableStream = require('stream').Writable

@@ -7,3 +6,3 @@ || require('readable-stream').Writable,

var utils = require('./utils');
var parseParams = require('./utils').parseParams;

@@ -18,3 +17,2 @@ function Busboy(opts) {

var self = this;
this._done = false;

@@ -33,3 +31,3 @@ this._parser = undefined;

else
EventEmitter.prototype.emit.apply(this, arguments);
WritableStream.prototype.emit.apply(this, arguments);
};

@@ -40,3 +38,3 @@

if (headers['content-type']) {
var parsed = utils.parseParams(headers['content-type']),
var parsed = parseParams(headers['content-type']),
matched, type;

@@ -43,0 +41,0 @@ for (var i = 0; i < TYPES_LEN; ++i) {

@@ -9,8 +9,9 @@ // TODO:

var ReadableStream = require('stream').Readable || require('readable-stream'),
Dicer = require('dicer'),
inherits = require('util').inherits,
jsencoding = require('../../deps/encoding/encoding');
inherits = require('util').inherits;
var utils = require('../utils');
var Dicer = require('dicer');
var parseParams = require('../utils').parseParams,
decodeText = require('../utils').decodeText;
var RE_BOUNDARY = /^boundary$/i,

@@ -22,3 +23,3 @@ RE_FIELD = /^form-data$/i,

Multipart.detect = /^multipart\//i;
Multipart.detect = /^multipart\/form-data/i;
function Multipart(boy, cfg) {

@@ -44,3 +45,6 @@ var boundary, i, len, self = this,

finished = false;
process.nextTick(function() { boy._done = true; boy.emit('finish'); });
process.nextTick(function() {
boy._done = true;
boy.emit('finish');
});
}

@@ -58,3 +62,3 @@ }

var nfiles = 0, nfields = 0, nends = 0, finished = false;
var nfiles = 0, nfields = 0, nends = 0, curFile, finished = false;

@@ -83,7 +87,7 @@ this._needDrain = false;

}
});
this.parser.on('part', function onPart(part) {
}).on('part', function onPart(part) {
if (++self._nparts > partsLimit) {
self.parser.removeListener('part', onPart);
self.parser.on('part', skipPart);
boy.hitPartsLimit = true;
boy.emit('partsLimit');

@@ -96,3 +100,3 @@ return skipPart(part);

if (header['content-type']) {
parsed = utils.parseParams(header['content-type'][0]);
parsed = parseParams(header['content-type'][0]);
contype = parsed[0].toLowerCase();

@@ -112,19 +116,10 @@ for (i = 0, len = parsed.length; i < len; ++i) {

if (header['content-disposition']) {
parsed = utils.parseParams(header['content-disposition'][0]);
parsed = parseParams(header['content-disposition'][0]);
if (!RE_FIELD.test(parsed[0]))
return skipPart(part);
for (i = 0, len = parsed.length; i < len; ++i) {
if (RE_NAME.test(parsed[i][0])) {
fieldname = parsed[i][1];
try {
fieldname = jsencoding.TextDecoder('utf8')
.decode(new Buffer(fieldname, 'binary'));
} catch(e) {}
} else if (RE_FILENAME.test(parsed[i][0])) {
filename = parsed[i][1];
try {
filename = jsencoding.TextDecoder('utf8')
.decode(new Buffer(filename, 'binary'));
} catch(e) {}
}
if (RE_NAME.test(parsed[i][0]))
fieldname = decodeText(parsed[i][1], 'binary', 'utf8');
else if (RE_FILENAME.test(parsed[i][0]))
filename = decodeText(parsed[i][1], 'binary', 'utf8');
}

@@ -151,4 +146,11 @@ } else

++nfiles;
if (!boy._events.file) {
self.parser._ignore();
return;
}
++nends;
var file = new FileStream(fileopts);
curFile = file;
file.on('end', function() {

@@ -182,2 +184,3 @@ --nends;

onEnd = function() {
curFile = undefined;
file.push(null);

@@ -210,8 +213,4 @@ };

onEnd = function() {
if (buffer.length && jsencoding.encodingExists(charset)) {
try {
buffer = jsencoding.TextDecoder(charset)
.decode(new Buffer(buffer, 'binary'));
} catch(e) {}
}
if (buffer.length)
buffer = decodeText(buffer, 'binary', charset);
boy.emit('field', fieldname, buffer, false, truncated);

@@ -224,5 +223,9 @@ --nends;

part.on('end', onEnd);
}).on('error', function(err) {
if (curFile)
curFile.emit('error', err);
});
});
this.parser.on('end', function() {
}).on('error', function(err) {
boy.emit('error', err);
}).on('finish', function() {
finished = true;

@@ -245,4 +248,8 @@ checkFinished();

var self = this;
if (this._nparts === 0 && !self._boy._done)
process.nextTick(function() { self._boy._done = true; self._boy.emit('finish'); });
if (this._nparts === 0 && !self._boy._done) {
process.nextTick(function() {
self._boy._done = true;
self._boy.emit('finish');
});
}
};

@@ -249,0 +256,0 @@

@@ -1,3 +0,3 @@

var jsencoding = require('../../deps/encoding/encoding'),
Decoder = require('../utils').Decoder;
var Decoder = require('../utils').Decoder,
decodeText = require('../utils').decodeText;

@@ -110,3 +110,3 @@ var RE_CHARSET = /^charset$/i;

if (key.length) {
this.boy.emit('field', convertVal(key, this.charset),
this.boy.emit('field', decodeText(key, 'binary', this.charset),
undefined,

@@ -160,4 +160,4 @@ keyTrunc,

}
this.boy.emit('field', convertVal(this._key, this.charset),
convertVal(this._val, this.charset),
this.boy.emit('field', decodeText(this._key, 'binary', this.charset),
decodeText(this._val, 'binary', this.charset),
this._keyTrunc,

@@ -211,3 +211,3 @@ this._valTrunc);

if (this._state === 'key' && this._key.length > 0) {
this.boy.emit('field', convertVal(this._key, this.charset),
this.boy.emit('field', decodeText(this._key, 'binary', this.charset),
undefined,

@@ -217,4 +217,4 @@ this._keyTrunc,

} else if (this._state === 'val') {
this.boy.emit('field', convertVal(this._key, this.charset),
convertVal(this._val, this.charset),
this.boy.emit('field', decodeText(this._key, 'binary', this.charset),
decodeText(this._val, 'binary', this.charset),
this._keyTrunc,

@@ -227,13 +227,2 @@ this._valTrunc);

function convertVal(val, charset) {
var ret = val;
if (val && val.length && jsencoding.encodingExists(charset)) {
try {
ret = jsencoding.TextDecoder(charset)
.decode(new Buffer(val, 'binary'));
} catch(e) {}
}
return ret;
}
module.exports = UrlEncoded;

@@ -57,8 +57,6 @@ var jsencoding = require('../deps/encoding/encoding');

if (charset) {
if (tmp.length && jsencoding.encodingExists(charset)) {
try {
tmp = jsencoding.TextDecoder(charset)
.decode(new Buffer(tmp.replace(RE_ENCODED, encodedReplacer),
'binary'));
} catch(e) {}
if (tmp.length) {
tmp = decodeText(tmp.replace(RE_ENCODED, encodedReplacer),
'binary',
charset);
}

@@ -80,8 +78,6 @@ charset = '';

if (tmp.length) {
if (charset && jsencoding.encodingExists(charset)) {
try {
tmp = jsencoding.TextDecoder(charset)
.decode(new Buffer(tmp.replace(RE_ENCODED, encodedReplacer),
'binary'));
} catch(e) {}
if (charset) {
tmp = decodeText(tmp.replace(RE_ENCODED, encodedReplacer),
'binary',
charset);
}

@@ -98,2 +94,15 @@ if (res[p] === undefined)

exports.Decoder = Decoder;
function decodeText(text, textEncoding, destEncoding) {
var ret = text;
if (text && jsencoding.encodingExists(destEncoding)) {
try {
ret = jsencoding.TextDecoder(destEncoding)
.decode(new Buffer(text, textEncoding));
} catch(e) {}
}
return ret;
}
exports.decodeText = decodeText;
var HEX = [

@@ -100,0 +109,0 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

{ "name": "busboy",
"version": "0.1.1",
"version": "0.2.0",
"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.6",
"dicer": "0.2.x",
"readable-stream": "1.1.x"

@@ -10,0 +10,0 @@ },

@@ -34,8 +34,8 @@ Description

busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log('File [' + fieldname +']: filename: ' + filename + ', encoding: ' + encoding);
console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding);
file.on('data', function(data) {
console.log('File [' + fieldname +'] got ' + data.length + ' bytes');
console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
});
file.on('end', function() {
console.log('File [' + fieldname +'] Finished');
console.log('File [' + fieldname + '] Finished');
});

@@ -116,8 +116,8 @@ });

busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log('File [' + fieldname +']: filename: ' + filename);
console.log('File [' + fieldname + ']: filename: ' + filename);
file.on('data', function(data) {
console.log('File [' + fieldname +'] got ' + data.length + ' bytes');
console.log('File [' + fieldname + '] got ' + data.length + ' bytes');
});
file.on('end', function() {
console.log('File [' + fieldname +'] Finished');
console.log('File [' + fieldname + '] Finished');
});

@@ -173,3 +173,3 @@ });

* **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.
* Note: if you listen for this event, you should always handle the `stream` no matter if you care about the file contents or not (e.g. you can simply just do `stream.resume();` if you want to discard the contents), otherwise the 'finish' event will never fire on the Busboy instance. However, if you don't care about **any** incoming files, you can simply not listen for the 'file' event at all and any/all files will be automatically and safely discarded (these discarded files do still count towards `files` and `parts` limits).
* `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.

@@ -176,0 +176,0 @@

@@ -98,2 +98,32 @@ var Busboy = require('..');

},
{ source: [
['-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
'Content-Disposition: form-data; name="file_name_0"',
'',
'super alpha file',
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
'Content-Disposition: form-data; name="file_name_1"',
'',
'super beta file',
'-----------------------------paZqsnEHRufoShdX6fh0lUhXBP4k',
'Content-Disposition: form-data; name="upload_file_0"; filename="1k_a.dat"',
'Content-Type: application/octet-stream',
'',
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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_name_0', 'super alpha file', false, false],
['field', 'file_name_1', 'super beta file', false, false],
],
events: ['field'],
what: 'Fields and (ignored) files'
},
];

@@ -116,13 +146,17 @@

busboy.on('field', function(key, val, keyTrunc, valTrunc) {
results.push(['field', key, val, keyTrunc, valTrunc]);
});
busboy.on('file', function(fieldname, stream, filename, encoding, mimeType) {
var nb = 0;
stream.on('data', function(d) {
nb += d.length;
}).on('end', function() {
results.push(['file', fieldname, nb, stream.truncated, filename, encoding, mimeType]);
if (v.events === undefined || v.events.indexOf('field') > -1) {
busboy.on('field', function(key, val, keyTrunc, valTrunc) {
results.push(['field', key, val, keyTrunc, valTrunc]);
});
});
}
if (v.events === undefined || v.events.indexOf('file') > -1) {
busboy.on('file', function(fieldname, stream, filename, encoding, mimeType) {
var nb = 0;
stream.on('data', function(d) {
nb += d.length;
}).on('end', function() {
results.push(['file', fieldname, nb, stream.truncated, filename, encoding, mimeType]);
});
});
}
busboy.on('finish', function() {

@@ -160,3 +194,5 @@ assert(finishes++ === 0, makeMsg(v.what, 'finish emitted multiple times'));

process.on('exit', function() {
assert(t === tests.length, makeMsg('_exit', 'Only finished ' + t + '/' + tests.length + ' tests'));
assert(t === tests.length,
makeMsg('_exit',
'Only finished ' + t + '/' + tests.length + ' tests'));
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc