{"_id":"@fastify/busboy@3.2.3","bugs":{"url":"https://github.com/fastify/busboy/issues"},"dist":{"shasum":"4a21ff2fbdf8b199cfac7230c1721adc9f5cba1f","tarball":"http://registry-npm.ywwl.com/@fastify/busboy/download/@fastify/busboy-3.2.3.tgz","fileCount":20,"integrity":"sha512-fmo/IKgkenPzz3qTKG+sIUXdF/Kv83AkvvOXJHPTHJeKJbat8SsL1ihUaFaDotqoEl4UZ1Lf8Eb/3vK6eaWX2A==","signatures":[{"sig":"MEYCIQDUgD0t6aNIHFZJX1e79ooWUD9A8/wLuJuzIKdYNnXX+gIhAKw75Kf7+6Ia34oYYO4oiEB8qIz7fAwm8LFpkOaxqOiX","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCSQXtWRNp24gTk3Ld3oMNG8HZTdUK54/otc2lFjpU7iQIhAIwqlVt+ON3+XGlxitCUO0APHb6SVWuvoeaOxkkQc3UD"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@fastify%2fbusboy@3.2.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":95912,"size":22539,"noattachment":false,"key":"/@fastify/busboy/-/@fastify/busboy-3.2.3.tgz"},"main":"index.js","name":"@fastify/busboy","type":"commonjs","types":"types/index.d.ts","author":{"name":"Brian White","email":"mscdex@mscdex.net"},"gitHead":"af57a2c6a892a85a507e3c39202f3208f95b86d9","license":"MIT","scripts":{"lint":"eslint","test":"npm run test:unit && npm run test:types","lint:fix":"eslint --fix","coveralls":"nyc report --reporter=lcov","test:unit":"c8 --check-coverage --statements 100 --branches 100 --functions 100 --lines 100 node --test","test:types":"tstyche","bench:dicer":"node bench/dicer/dicer-bench-multipart-parser.js","bench:busboy":"cd benchmarks && npm install && npm run benchmark-fastify"},"version":"3.2.3","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"38d4bda7-17ed-405e-bce4-d6564a472699"}},"homepage":"https://github.com/fastify/busboy#readme","keywords":["uploads","forms","multipart","form-data"],"standard":{"ignore":["bench"],"globals":["describe","it"]},"repository":{"url":"git+https://github.com/fastify/busboy.git","type":"git"},"_npmVersion":"11.19.0","description":"A streaming parser for HTML form data for node.js","directories":{},"maintainers":[{"name":"eomm","email":"behemoth89@gmail.com"}],"_nodeVersion":"24.21.0","contributors":[{"url":"https://github.com/kibertoad","name":"Igor Savin","email":"kibertoad@gmail.com"},{"url":"https://github.com/uzlopak","name":"Aras Abbasi","email":"aras.abbasi@gmail.com"}],"_hasShrinkwrap":false,"devDependencies":{"c8":"^12.0.0","tslib":"^2.8.1","busboy":"^1.6.0","eslint":"^9.39.0","snazzy":"^9.0.0","tstyche":"^7.0.0","tinybench":"^6.0.0","typescript":"~6.0.2","@types/node":"^26.0.1","neostandard":"^0.12.0","photofinish":"^1.8.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/busboy_3.2.3_1791626812182_0.021547866403941685"},"readme":"# busboy\n\n[![Build Status](https://github.com/fastify/busboy/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/busboy/actions)\n[![NPM version](https://img.shields.io/npm/v/@fastify/busboy.svg?style=flat)](https://www.npmjs.com/package/@fastify/busboy)\n[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)\n[![Security Responsible Disclosure](https://img.shields.io/badge/Security-Responsible%20Disclosure-yellow.svg)](https://github.com/fastify/.github/blob/main/SECURITY.md)\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\nRequirements\n============\n\n* [Node.js](https://nodejs.org/) 10+\n\nInstall\n=======\n\n```sh\nnpm 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\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* **limit**() - Emitted when a file exceeds the configured `fileSize` limit. You can listen on the file stream to handle it:\n\n```js\nbusboy.on('file', (fieldname, stream) => {\n  stream.on('limit', () => {\n    console.log('File size exceeded')\n  })\n})\n```\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\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":1791626812280,"_cnpm_publish_time":1791626812280,"dist-tags":{"latest":"3.2.5","next":"1.0.0-next2"}}