Comparing version 0.0.4 to 0.0.5
@@ -84,3 +84,3 @@ // TODO: | ||
if (header['content-transfer-encoding']) | ||
encoding = header['content-transfer-encoding'].toLowerCase(); | ||
encoding = header['content-transfer-encoding'][0].toLowerCase(); | ||
else | ||
@@ -97,3 +97,3 @@ encoding = '7bit'; | ||
var file = new FileStream(); | ||
boy.emit('file', fieldname, file, filename); | ||
boy.emit('file', fieldname, file, filename, encoding); | ||
@@ -100,0 +100,0 @@ onData = function(data) { |
{ "name": "busboy", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"author": "Brian White <mscdex@mscdex.net>", | ||
@@ -4,0 +4,0 @@ "description": "A streaming parser for HTML form data for node.js", |
@@ -34,4 +34,4 @@ | ||
var busboy = new Busboy({ headers: req.headers }); | ||
busboy.on('file', function(fieldname, file, filename) { | ||
console.log('File [' + fieldname +']: filename: ' + filename); | ||
busboy.on('file', function(fieldname, file, filename, encoding) { | ||
console.log('File [' + fieldname +']: filename: ' + filename + ', encoding: ' + encoding); | ||
file.on('data', function(data) { | ||
@@ -77,2 +77,49 @@ console.log('File [' + fieldname +'] got ' + data.length + ' bytes'); | ||
* Parsing `multipart/form-data` & saving files. Keep track of the point where the files are all properly saved to disk. | ||
```javascript | ||
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 ...'); | ||
busboy.on('file', function(fieldname, file, filename, encoding) { | ||
++infiles; | ||
onFile(fieldname, file, filename, encoding, 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!"); | ||
} | ||
}); | ||
}); | ||
busboy.once('end', function() { | ||
console.log('Done parsing form!'); | ||
done = true; | ||
}); | ||
req.pipe(busboy); | ||
} | ||
}).listen(8000, function() { | ||
console.log('Listening for requests'); | ||
}); | ||
function onFile(fieldname, file, filename, encoding, next) { | ||
// or save at some other location | ||
var fstream = fs.createWriteStream(path.join(os.tmpDir(), path.basename(filename))); | ||
file.once('end', function() { | ||
console.log(fieldname + '(' + filename + ') EOF'); | ||
}); | ||
fstream.once('close', function() { | ||
console.log(fieldname + '(' + filename + ') written to disk'); | ||
next(); | ||
}); | ||
console.log(fieldname + '(' + filename + ') start saving'); | ||
file.pipe(fstream); | ||
} | ||
``` | ||
* Parsing (urlencoded) with default options: | ||
@@ -145,3 +192,3 @@ | ||
* **file**(< _string_ >fieldname, < _ReadableStream_ >stream, < _string_ >filename) - Emitted for each new file form field found. | ||
* **file**(< _string_ >fieldname, < _ReadableStream_ >stream, < _string_ >filename, < _string_ >transferEncoding) - Emitted for each new file form field found. `transferEncoding` contains the 'Content-Transfer-Encoding' value for the file stream. | ||
@@ -148,0 +195,0 @@ * **field**(< _string_ >fieldname, < _string_ >value, < _boolean_ >valueTruncated, < _boolean_ >fieldnameTruncated) - Emitted for each new non-file field found. |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
649210
222
0