Socket
Socket
Sign inDemoInstall

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.0.4 to 0.0.5

4

lib/types/multipart.js

@@ -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.

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