Comparing version 0.0.14 to 0.0.15
@@ -61,2 +61,4 @@ var fs = require('fs'), | ||
Busboy.prototype._write = function(chunk, encoding, cb) { | ||
if (!this._parser) | ||
return cb(new Error('Not ready to parse. Missing Content-Type?')); | ||
this._parser.write(chunk, cb); | ||
@@ -63,0 +65,0 @@ }; |
@@ -50,3 +50,3 @@ var jsencoding = require('../../deps/encoding/encoding'), | ||
if (this._fields === this.fieldsLimit) { | ||
if (!boy.hitFieldsLimit) { | ||
if (!this.boy.hitFieldsLimit) { | ||
this.boy.hitFieldsLimit = true; | ||
@@ -53,0 +53,0 @@ this.boy.emit('fieldsLimit'); |
@@ -35,2 +35,4 @@ var jsencoding = require('../deps/encoding/encoding'); | ||
} else { | ||
if (escaping && inquote) | ||
tmp += '\\'; | ||
escaping = false; | ||
@@ -37,0 +39,0 @@ if ((state === 'charset' || state === 'lang') && str[i] === "'") { |
{ "name": "busboy", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"author": "Brian White <mscdex@mscdex.net>", | ||
@@ -4,0 +4,0 @@ "description": "A streaming parser for HTML form data for node.js", |
@@ -75,47 +75,28 @@ Description | ||
* Parsing `multipart/form-data` & saving files. Keep track of the point where the files are all properly saved to disk. | ||
* Save all incoming files to disk: | ||
```javascript | ||
var http = require('http'), | ||
os = require('os'); | ||
var Busboy = require('busboy'); | ||
http.createServer(function(req, res) { | ||
if (req.method === 'POST') { | ||
var infiles = 0, outfiles = 0, done = false, | ||
busboy = new Busboy({ headers: req.headers }); | ||
console.log('Start parsing form ...'); | ||
var busboy = new Busboy({ headers: req.headers }); | ||
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { | ||
++infiles; | ||
onFile(fieldname, file, filename, function() { | ||
++outfiles; | ||
if (done) | ||
console.log(outfiles + '/' + infiles + ' parts written to disk'); | ||
if (done && infiles === outfiles) { | ||
// ACTUAL EXIT CONDITION | ||
console.log('All parts written to disk'); | ||
res.writeHead(200, { 'Connection': 'close' }); | ||
res.end("That's all folks!"); | ||
} | ||
}); | ||
var saveTo = path.join(os.tmpDir(), path.basename(fieldname)); | ||
file.pipe(fs.createWriteStream(saveTo)); | ||
}); | ||
busboy.on('end', function() { | ||
console.log('Done parsing form!'); | ||
done = true; | ||
res.writeHead(200, { 'Connection': 'close' }); | ||
res.end('That's all folks!'); | ||
}); | ||
req.pipe(busboy); | ||
return req.pipe(busboy); | ||
} | ||
res.writeHead(404); | ||
res.end(); | ||
}).listen(8000, function() { | ||
console.log('Listening for requests'); | ||
}); | ||
function onFile(fieldname, file, filename, next) { | ||
// or save at some other location | ||
var fstream = fs.createWriteStream(path.join(os.tmpDir(), path.basename(filename))); | ||
file.on('end', function() { | ||
console.log(fieldname + '(' + filename + ') EOF'); | ||
}); | ||
fstream.on('close', function() { | ||
console.log(fieldname + '(' + filename + ') written to disk'); | ||
next(); | ||
}); | ||
console.log(fieldname + '(' + filename + ') start saving'); | ||
file.pipe(fstream); | ||
} | ||
``` | ||
@@ -122,0 +103,0 @@ |
var parseParams = require('../lib/utils').parseParams; | ||
var path = require('path'), | ||
assert = require('assert'); | ||
assert = require('assert'), | ||
inspect = require('util').inspect; | ||
@@ -49,6 +50,16 @@ var group = path.basename(__filename, '.js') + '/'; | ||
}, | ||
{ source: 'text/plain; filename="C:\\folder\\test.png"', | ||
expected: ['text/plain', ['filename', 'C:\\folder\\test.png']], | ||
what: 'Unescaped backslashes should be considered backslashes' | ||
}, | ||
{ source: 'text/plain; filename="John \\"Magic\\" Smith.png"', | ||
expected: ['text/plain', ['filename', 'John "Magic" Smith.png']], | ||
what: 'Escaped double-quotes should be considered double-quotes' | ||
}, | ||
].forEach(function(v) { | ||
var result = parseParams(v.source), | ||
msg = '[' + group + v.what + ']: parsed parameters mismatch'; | ||
msg = '[' + group + v.what + ']: parsed parameters mismatch.\n' | ||
+ 'Saw: ' + inspect(result) + '\n' | ||
+ 'Expected: ' + inspect(v.expected); | ||
assert.deepEqual(result, v.expected, msg); | ||
}); |
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
5305
664044
212