{"name":"@fastify/busboy","version":"1.0.0-next2","private":false,"author":{"name":"Brian White","email":"mscdex@mscdex.net"},"contributors":[{"name":"Igor Savin","email":"kibertoad@gmail.com","url":"https://github.com/kibertoad"},{"name":"Aras Abbasi","email":"aras.abbasi@gmail.com","url":"https://github.com/uzlopak"}],"description":"A streaming parser for HTML form data for node.js","main":"lib/main","types":"lib/main.d.ts","scripts":{"bench:busboy":"node bench/fastify-busboy-bench.js","bench:dicer":"node bench/dicer/dicer-bench-multipart-parser.js","coveralls":"nyc report --reporter=lcov","lint":"npm run lint:standard","lint:everything":"npm run lint && npm run test:types","lint:fix":"standard --fix","lint:standard":"standard --verbose | snazzy","test:mocha":"mocha test","test:types":"tsd","test:coverage":"nyc npm run test","test":"npm run test:mocha"},"engines":{"node":">=10.17.0"},"dependencies":{"text-decoding":"^1.0.0"},"devDependencies":{"@types/node":"^16.11.10","busboy":"^0.3.1","chai":"^4.3.4","eslint":"^7.32.0","eslint-config-standard":"^16.0.3","eslint-plugin-node":"^11.1.0","mocha":"^9.1.3","nyc":"^15.1.0","photofinish":"^1.8.0","snazzy":"^9.0.0","standard":"^16.0.4","tsd":"^0.19.0","typescript":"^4.5.2"},"keywords":["uploads","forms","multipart","form-data"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/fastify/busboy.git"},"tsd":{"directory":"test/types","compilerOptions":{"esModuleInterop":false,"module":"commonjs","target":"ES2017"}},"standard":{"globals":["describe","it"],"ignore":["bench"]},"readme":"# busboy\n\n<div align=\"center\">\n\n[![Build Status](https://github.com/fastify/busboy/workflows/ci/badge.svg)](https://github.com/fastify/busboy/actions)\n[![Coverage Status](https://coveralls.io/repos/fastify/busboy/badge.svg?branch=master)](https://coveralls.io/r/fastify/busboy?branch=master)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\n[![Known Vulnerabilities](https://snyk.io/test/github/fastify/busboy/badge.svg)](https://snyk.io/test/github/fastify/busboy)\n[![Security Responsible Disclosure](https://img.shields.io/badge/Security-Responsible%20Disclosure-yellow.svg)](https://github.com/nodejs/security-wg/blob/HEAD/processes/responsible_disclosure_template.md)\n\n</div>\n\n<div align=\"center\">\n\n[![NPM version](https://img.shields.io/npm/v/@fastify/busboy.svg?style=flat)](https://www.npmjs.com/package/@fastify/busboy)\n[![NPM downloads](https://img.shields.io/npm/dm/@fastify/busboy.svg?style=flat)](https://www.npmjs.com/package/@fastify/busboy)\n\n</div>\n\nDescription\n===========\n\nA Node.js module for parsing incoming HTML form data.\n\nThis is an officially supported fork by [fastify](https://github.com/fastify/) organization of the amazing library [originally created](https://github.com/mscdex/busboy) by Brian White,\naimed at addressing long-standing issues with it.\n\nBenchmark (Mean time for 500 Kb payload, 2000 cycles, 1000 cycle warmup):\n\n| Library               | Mean time in nanoseconds |\n|-----------------------|--------------------------|\n| busboy 0.31           |                          |\n| @fastify/busboy 1.0.0 |                          |\n\n[Changelog](https://github.com/fastify/busboy/blob/master/CHANGELOG.md) since busboy 0.31.\n\nRequirements\n============\n\n* [node.js](http://nodejs.org/) -- v10 or newer\n\n\nInstall\n=======\n\n    npm install @fastify/busboy\n\n\nExamples\n========\n\n* Parsing (multipart) with default options:\n\n```javascript\nconst http = require('http');\nconst { inspect } = require('util');\nconst Busboy = require('busboy');\n\nhttp.createServer((req, res) => {\n  if (req.method === 'POST') {\n    const busboy = new Busboy({ headers: req.headers });\n    busboy.on('file', (fieldname, file, filename, encoding, mimetype) => {\n      console.log(`File [${fieldname}]: filename: ${filename}, encoding: ${encoding}, mimetype: ${mimetype}`);\n      file.on('data', data => {\n        console.log(`File [${fieldname}] got ${data.length} bytes`);\n      });\n      file.on('end', () => {\n        console.log(`File [${fieldname}] Finished`);\n      });\n    });\n    busboy.on('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {\n      console.log(`Field [${fieldname}]: value: ${inspect(val)}`);\n    });\n    busboy.on('finish', () => {\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, () => {\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\nconst http = require('http');\nconst path = require('path');\nconst os = require('os');\nconst fs = require('fs');\n\nconst Busboy = require('busboy');\n\nhttp.createServer(function(req, res) {\n  if (req.method === 'POST') {\n    const 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\nconst http = require('http');\nconst { inspect } = require('util');\n\nconst Busboy = require('busboy');\n\nhttp.createServer(function(req, res) {\n  if (req.method === 'POST') {\n    const 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    * The property `bytesRead` informs about the number of bytes that have been read so far.\n\n* **field**(< _string_ >fieldname, < _string_ >value, < _boolean_ >fieldnameTruncated, < _boolean_ >valueTruncated, < _string_ >transferEncoding, < _string_ >mimeType) - 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.\n\n    * The constructor takes 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        * **autoDestroy** - _boolean_ - Whether this stream should automatically call .destroy() on itself after ending. (Default: false).\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        * **preservePath** - _boolean_ - If paths in the multipart 'filename' field shall be preserved. (Default: false).\n\n        * **isPartAFile** - __function__ - Use this function to override the default file detection functionality. It has following parameters:\n\n            * fieldName - __string__ The name of the field.\n\n            * contentType - __string__ The content-type of the part, e.g. `text/plain`, `image/jpeg`, `application/octet-stream`\n\n            * fileName - __string__ The name of a file supplied by the part.\n\n          (Default: `(fieldName, contentType, fileName) => (contentType === 'application/octet-stream' || fileName !== undefined)`)\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: 1 MiB, which is 1024 x 1024 bytes).\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\n\n            * **headerSize** - _integer_ - For multipart forms, the max size of a multipart header **Default:** 81920.\n\n    * The constructor can throw errors:\n\n        * **Busboy expected an options-Object.** - Busboy expected an Object as first parameters.\n\n        * **Busboy expected an options-Object with headers-attribute.** - The first parameter is lacking of a headers-attribute.\n\n        * **Limit $limit is not a valid number** - Busboy expected the desired limit to be of type number. Busboy throws this Error to prevent a potential security issue by falling silently back to the Busboy-defaults. Potential source for this Error can be the direct use of environment variables without transforming them to the type number. \n\n        * **Unsupported Content-Type.** - The `Content-Type` isn't one Busboy can parse.\n\n        * **Missing Content-Type-header.** - The provided headers don't include `Content-Type` at all.\n","readmeFilename":"README.md","gitHead":"a7a876b64b6198f1b4ca65577ed1287ae6bca0bd","bugs":{"url":"https://github.com/fastify/busboy/issues"},"homepage":"https://github.com/fastify/busboy#readme","_id":"@fastify/busboy@1.0.0-next2","_nodeVersion":"16.12.0","_npmVersion":"8.1.0","dist":{"integrity":"sha512-GF+zJ8zzl8Ai+EL35EfMgZZU/XO3dn+excmmsxWq9OgEsEQhjxDS/V3svGcyOLz0+RLs15/mESEyVcTQMtgI8A==","shasum":"c4efcda1a0f27b7167718d25a38acefabe5f2a02","tarball":"http://registry-npm.ywwl.com/@fastify/busboy/download/@fastify/busboy-1.0.0-next2.tgz","fileCount":13,"unpackedSize":61232,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhq9IfCRA9TVsSAnZWagAAPEQP/jmXUt7Sk14zFL5Zc2Wp\ng1PmXwtxqEXw7Z63kiC5TDQ1IG6/1xTdNsiLEVPL45kTXBWTYZ32sVsQTIUY\nezCLIsOZzznzzrSRize2tVrK28xs6bem04GurMXepLqHGhrzeIaU/cUcXOWA\nGe5NsGlO5pNQfeq53sVSBVEhPOBB+T/+dE5G5BcdyeyDiAGQYH8bKPhM5pmN\n35m6qw6VYFYSJaHbGMl4ZmfSAmVXiCfntbktLhnjerPYxoNhbMILTeZiQra9\nTPdSBT/4wBbGhDXL5VUwrzJ/BQzs1OFj9mcm3Vs2Zdi3/1PLOThokPZo3map\nO1uTcETwE3SEAxpbSGodTbIds/hzi+ebkCo4avNrhUfjK2dlT6sviqfuIY8m\nOgvAArKWjdk9cZufo4ardCsWsxMruzS4yYdRNlbu/ySxLKt0T9D4TcI8zIhO\n2JAf4DApnpdrxOM3f59+syTIlu73/bkji7z1fJ+nWb8sDW18sfxTQ/d6wRZR\nGLCl6Kc1XaPxkkyMS2UCSHYDk65OHmFeNiHDgaH9aI1jUWSPLYHdMhS+NjG/\n07zg6RVOy+JmEpHFJQNAQGdFx5akcF+qugXTT2UljhxkaStCthbLgVde949j\nbiB0w0nLjjLQHbbC4ar7QfpkzdSyQ49c3KqJ5E+++72TIHBmH5dzAkb/W/Vt\nn2LM\r\n=arzz\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAilCMhMy9P3qakzQ1kEnTrQIaw5VmqJ+SL9bljUG58fAiEAnAO/imWzo06lsbnA6eoMkGOyU1VrdN8ZsxmTl9UagZ4="}],"size":15443,"noattachment":false,"key":"/@fastify/busboy/-/@fastify/busboy-1.0.0-next2.tgz"},"_npmUser":{"name":"kibertoad","email":"iselwin@gmail.com"},"directories":{},"maintainers":[{"name":"starptech","email":"deusdustin@gmail.com"},{"name":"delvedor","email":"tommydelved@gmail.com"},{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"allevo","email":"tomallevi@gmail.com"},{"name":"jsumners","email":"james.sumners@gmail.com"},{"name":"zekth","email":"vince.legoff@gmail.com"},{"name":"ethan_arrowood","email":"ethan@arrowood.dev"},{"name":"eomm","email":"behemoth89@gmail.com"},{"name":"fox1t","email":"maksim@sinik.it"},{"name":"salmanm","email":"salmanmitha@gmail.com"},{"name":"davidmarkclements","email":"david.mark.clements@gmail.com"},{"name":"airhorns","email":"harry@harry.me"},{"name":"kibertoad","email":"iselwin@gmail.com"},{"name":"climba03003","email":"kaka@kakawebsitedemo.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/busboy_1.0.0-next2_1638650399720_0.4605750121075931"},"_hasShrinkwrap":false,"publish_time":1638650399966,"_cnpm_publish_time":1638650399966,"dist-tags":{"latest":"3.2.5","next":"1.0.0-next2"}}