{"name":"busboy","version":"0.2.9","author":{"name":"Brian White","email":"mscdex@mscdex.net"},"description":"A streaming parser for HTML form data for node.js","main":"./lib/main","dependencies":{"dicer":"0.2.3","readable-stream":"1.1.x"},"scripts":{"test":"node test/test.js"},"engines":{"node":">=0.8.0"},"keywords":["uploads","forms","multipart","form-data"],"licenses":[{"type":"MIT","url":"http://github.com/mscdex/busboy/raw/master/LICENSE"}],"repository":{"type":"git","url":"http://github.com/mscdex/busboy.git"},"readme":"Description\n===========\n\nA node.js module for parsing incoming HTML form data.\n\n\nRequirements\n============\n\n* [node.js](http://nodejs.org/) -- v0.8.0 or newer\n\n\nInstall\n=======\n\n    npm install busboy\n\n\nExamples\n========\n\n* Parsing (multipart) with default options:\n\n```javascript\nvar http = require('http'),\n    inspect = require('util').inspect;\n\nvar Busboy = require('busboy');\n\nhttp.createServer(function(req, res) {\n  if (req.method === 'POST') {\n    var busboy = new Busboy({ headers: req.headers });\n    busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {\n      console.log('File [' + fieldname + ']: filename: ' + filename + ', encoding: ' + encoding + ', mimetype: ' + mimetype);\n      file.on('data', function(data) {\n        console.log('File [' + fieldname + '] got ' + data.length + ' bytes');\n      });\n      file.on('end', function() {\n        console.log('File [' + fieldname + '] Finished');\n      });\n    });\n    busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) {\n      console.log('Field [' + fieldname + ']: value: ' + inspect(val));\n    });\n    busboy.on('finish', function() {\n      console.log('Done parsing form!');\n      res.writeHead(303, { Connection: 'close', Location: '/' });\n      res.end();\n    });\n    req.pipe(busboy);\n  } else if (req.method === 'GET') {\n    res.writeHead(200, { Connection: 'close' });\n    res.end('<html><head></head><body>\\\n               <form method=\"POST\" enctype=\"multipart/form-data\">\\\n                <input type=\"text\" name=\"textfield\"><br />\\\n                <input type=\"file\" name=\"filefield\"><br />\\\n                <input type=\"submit\">\\\n              </form>\\\n            </body></html>');\n  }\n}).listen(8000, function() {\n  console.log('Listening for requests');\n});\n\n// Example output, using http://nodejs.org/images/ryan-speaker.jpg as the file:\n//\n// Listening for requests\n// File [filefield]: filename: ryan-speaker.jpg, encoding: binary\n// File [filefield] got 11971 bytes\n// Field [textfield]: value: 'testing! :-)'\n// File [filefield] Finished\n// Done parsing form!\n```\n\n* Save all incoming files to disk:\n\n```javascript\nvar http = require('http'),\n    path = require('path'),\n    os = require('os');\n\nvar Busboy = require('busboy');\n\nhttp.createServer(function(req, res) {\n  if (req.method === 'POST') {\n    var busboy = new Busboy({ headers: req.headers });\n    busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {\n      var saveTo = path.join(os.tmpDir(), path.basename(fieldname));\n      file.pipe(fs.createWriteStream(saveTo));\n    });\n    busboy.on('finish', function() {\n      res.writeHead(200, { 'Connection': 'close' });\n      res.end(\"That's all folks!\");\n    });\n    return req.pipe(busboy);\n  }\n  res.writeHead(404);\n  res.end();\n}).listen(8000, function() {\n  console.log('Listening for requests');\n});\n```\n\n* Parsing (urlencoded) with default options:\n\n```javascript\nvar http = require('http'),\n    inspect = require('util').inspect;\n\nvar Busboy = require('busboy');\n\nhttp.createServer(function(req, res) {\n  if (req.method === 'POST') {\n    var busboy = new Busboy({ headers: req.headers });\n    busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {\n      console.log('File [' + fieldname + ']: filename: ' + filename);\n      file.on('data', function(data) {\n        console.log('File [' + fieldname + '] got ' + data.length + ' bytes');\n      });\n      file.on('end', function() {\n        console.log('File [' + fieldname + '] Finished');\n      });\n    });\n    busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) {\n      console.log('Field [' + fieldname + ']: value: ' + inspect(val));\n    });\n    busboy.on('finish', function() {\n      console.log('Done parsing form!');\n      res.writeHead(303, { Connection: 'close', Location: '/' });\n      res.end();\n    });\n    req.pipe(busboy);\n  } else if (req.method === 'GET') {\n    res.writeHead(200, { Connection: 'close' });\n    res.end('<html><head></head><body>\\\n               <form method=\"POST\">\\\n                <input type=\"text\" name=\"textfield\"><br />\\\n                <select name=\"selectfield\">\\\n                  <option value=\"1\">1</option>\\\n                  <option value=\"10\">10</option>\\\n                  <option value=\"100\">100</option>\\\n                  <option value=\"9001\">9001</option>\\\n                </select><br />\\\n                <input type=\"checkbox\" name=\"checkfield\">Node.js rules!<br />\\\n                <input type=\"submit\">\\\n              </form>\\\n            </body></html>');\n  }\n}).listen(8000, function() {\n  console.log('Listening for requests');\n});\n\n// Example output:\n//\n// Listening for requests\n// Field [textfield]: value: 'testing! :-)'\n// Field [selectfield]: value: '9001'\n// Field [checkfield]: value: 'on'\n// Done parsing form!\n```\n\n\nAPI\n===\n\n_Busboy_ is a _Writable_ stream\n\nBusboy (special) events\n-----------------------\n\n* **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.\n    * 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).\n    * If a configured file size limit was reached, `stream` will both have a boolean property `truncated` (best checked at the end of the stream) and emit a 'limit' event to notify you when this happens.\n\n* **field**(< _string_ >fieldname, < _string_ >value, < _boolean_ >fieldnameTruncated, < _boolean_ >valueTruncated) - Emitted for each new non-file field found.\n\n* **partsLimit**() - Emitted when specified `parts` limit has been reached. No more 'file' or 'field' events will be emitted.\n\n* **filesLimit**() - Emitted when specified `files` limit has been reached. No more 'file' events will be emitted.\n\n* **fieldsLimit**() - Emitted when specified `fields` limit has been reached. No more 'field' events will be emitted.\n\n\nBusboy methods\n--------------\n\n* **(constructor)**(< _object_ >config) - Creates and returns a new Busboy instance with the following valid `config` settings:\n\n    * **headers** - _object_ - These are the HTTP headers of the incoming request, which are used by individual parsers.\n\n    * **highWaterMark** - _integer_ - highWaterMark to use for this Busboy instance (Default: WritableStream default).\n\n    * **fileHwm** - _integer_ - highWaterMark to use for file streams (Default: ReadableStream default).\n\n    * **defCharset** - _string_ - Default character set to use when one isn't defined (Default: 'utf8').\n\n    * **limits** - _object_ - Various limits on incoming data. Valid properties are:\n\n        * **fieldNameSize** - _integer_ - Max field name size (in bytes) (Default: 100 bytes).\n\n        * **fieldSize** - _integer_ - Max field value size (in bytes) (Default: 1MB).\n\n        * **fields** - _integer_ - Max number of non-file fields (Default: Infinity).\n\n        * **fileSize** - _integer_ - For multipart forms, the max file size (in bytes) (Default: Infinity).\n\n        * **files** - _integer_ - For multipart forms, the max number of file fields (Default: Infinity).\n\n        * **parts** - _integer_ - For multipart forms, the max number of parts (fields + files) (Default: Infinity).\n\n        * **headerPairs** - _integer_ - For multipart forms, the max number of header key=>value pairs to parse **Default:** 2000 (same as node's http).\n","readmeFilename":"README.md","bugs":{"url":"https://github.com/mscdex/busboy/issues"},"homepage":"https://github.com/mscdex/busboy","_id":"busboy@0.2.9","_shasum":"a0a181e78b19dee76974560f55843b09eaea7376","_from":"https://registry.npmjs.org/busboy/-/busboy-0.2.9.tgz","_resolved":"https://registry.npmjs.org/busboy/-/busboy-0.2.9.tgz"}