{"name":"@fastify/busboy","version":"3.1.1","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","type":"commonjs","types":"lib/main.d.ts","scripts":{"bench:busboy":"cd benchmarks && npm install && npm run benchmark-fastify","bench:dicer":"node bench/dicer/dicer-bench-multipart-parser.js","coveralls":"nyc report --reporter=lcov","lint":"npm run lint:standard","lint:fix":"standard --fix","lint:standard":"standard --verbose | snazzy","test:unit":"c8 --statements 98 --branches 97 --functions 96 --lines 98 node --test","test:types":"tsd","test":"npm run test:unit && npm run test:types"},"devDependencies":{"@types/node":"^22.0.0","busboy":"^1.6.0","c8":"^10.1.2","photofinish":"^1.8.0","snazzy":"^9.0.0","standard":"^17.1.0","tinybench":"^3.0.0","tsd":"^0.31.0","typescript":"~5.7.2"},"keywords":["uploads","forms","multipart","form-data"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/fastify/busboy.git"},"bugs":{"url":"https://github.com/fastify/busboy/issues"},"homepage":"https://github.com/fastify/busboy#readme","tsd":{"directory":"test/types","compilerOptions":{"esModuleInterop":false,"module":"commonjs","target":"ES2017"}},"standard":{"globals":["describe","it"],"ignore":["bench"]},"_id":"@fastify/busboy@3.1.1","gitHead":"538858576084ac23572cf445404d060d54fa7ec8","_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-5DGmA8FTdB2XbDeEwc/5ZXBl6UbBAyBOOLlPuBnZ/N1SwdH9Ii+cOX3tBROlDgcTXxjOYnLMVoKk9+FXAw0CJw==","shasum":"af3aea7f1e52ec916d8b5c9dcc0f09d4c060a3fc","tarball":"http://registry-npm.ywwl.com/@fastify/busboy/download/@fastify/busboy-3.1.1.tgz","fileCount":18,"unpackedSize":80126,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBVqHFpd5tkhCLDdKHiOnLCUnvWSbYw7YP+X8FyX7K+uAiB1TdfAdEmnSy75QCs/SE39JO1A5tknWIiBYLVb6y7rpQ=="}],"size":20247,"noattachment":false,"key":"/@fastify/busboy/-/@fastify/busboy-3.1.1.tgz"},"_npmUser":{"name":"gurgunday","email":"hey@gurgun.day"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/busboy_3.1.1_1734876423350_0.46447468815120874"},"_hasShrinkwrap":false,"readme":"# busboy\n\n<div align=\"center\">\n\n[![Build Status](https://github.com/fastify/busboy/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/busboy/actions)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\n[![Security Responsible Disclosure](https://img.shields.io/badge/Security-Responsible%20Disclosure-yellow.svg)](https://github.com/fastify/.github/blob/main/SECURITY.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               | Version | Mean time in nanoseconds (less is better) |\n|-----------------------|---------|-------------------------------------------|\n| busboy                | 0.3.1   | `340114`                                  |\n| @fastify/busboy       | 1.0.0   | `270984`                                  |\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/) 10+\n\n\nInstall\n=======\n\n    npm i @fastify/busboy\n\n\nExamples\n========\n\n* Parsing (multipart) with default options:\n\n```javascript\nconst http = require('node:http');\nconst { inspect } = require('node:util');\nconst Busboy = require('@fastify/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('node:http');\nconst path = require('node:path');\nconst os = require('node:os');\nconst fs = require('node:fs');\n\nconst Busboy = require('@fastify/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('node:http');\nconst { inspect } = require('node:util');\n\nconst Busboy = require('@fastify/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","publish_time":1734876423534,"maintainers":[{"name":"starptech","email":"deusdustin@gmail.com"},{"name":"simoneb","email":"simone.busoli@gmail.com"},{"name":"coopflow","email":"community@coopflow.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":"rafaelgss","email":"rafael.nunu@hotmail.com"},{"name":"eomm","email":"behemoth89@gmail.com"},{"name":"fox1t","email":"maksim@sinik.it"},{"name":"airhorns","email":"harry@harry.me"},{"name":"kibertoad","email":"iselwin@gmail.com"},{"name":"climba03003","email":"kaka@kakawebsitedemo.com"},{"name":"galvez","email":"jonasgalvez@gmail.com"},{"name":"simenb","email":"sbekkhus91@gmail.com"},{"name":"gurgunday","email":"hey@gurgun.day"},{"name":"metcoder95","email":"me@metcoder.dev"}],"_cnpm_publish_time":1734876423534,"dist-tags":{"latest":"3.2.5","next":"1.0.0-next2"}}