{"name":"@fastify/busboy","version":"1.0.0-next1","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:dicer":"node deps/dicer/bench/dicer-bench-multipart-parser.js","coveralls":"nyc report --reporter=lcov","lint":"eslint .","lint:everything":"npm run lint && npm run test:types","test:mocha":"mocha test","test:types":"tsd","test:coverage":"nyc npm run test","test":"npm run test:mocha"},"engines":{"node":">=10.17.0"},"devDependencies":{"@types/node":"^16.11.10","chai":"^4.3.4","eslint":"^8.3.0","eslint-plugin-node":"^11.1.0","mocha":"^9.1.3","nyc":"^15.1.0","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"}},"gitHead":"02eb3ce5b144ec8b72ad333ea030d50997e86a15","bugs":{"url":"https://github.com/fastify/busboy/issues"},"homepage":"https://github.com/fastify/busboy#readme","_id":"@fastify/busboy@1.0.0-next1","_nodeVersion":"16.13.0","_npmVersion":"8.1.0","dist":{"integrity":"sha512-pmH0hRjMEfoF9kF/boEwvJdrW4y0/INdzUTQdchcN5l7s0lxvNtFgMH5g1ofQSP0cLsNcxbpRGbPwVHOv+vnxA==","shasum":"3d3d0f7b6ed9f40ffe21eb433bc353889281752f","tarball":"http://registry-npm.ywwl.com/@fastify/busboy/download/@fastify/busboy-1.0.0-next1.tgz","fileCount":15,"unpackedSize":680517,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhpVJZCRA9TVsSAnZWagAAoaoP/RbiNA4wMk/Oq/uCSEX3\n1aPPBN3p12bI0qt/bkt+Z0XFeK0aIxhfALDCuVWF2gpxuNlmELOh5ziIM/g4\nQx8dor7EbwhQVmdTcE6SNmJYwJI3eQInHQWwAgMT4SlHrgqOgr+qGkioRHlY\n7fCrSja78PhyA+nxPFjPr4eQwxHI6KuaoJKjXPZ+fNrIh10x66qlhf5zlaaC\nLsqLY8WmddqLuMSJ098UnKUy5SrKR76y1yW3H1riTJmTj0IV6fvrzOPok1Bi\nruRGD6140A7kVBFUp4LLrTQdraakHaWK9Zs4SVSbOoBu7QyJK5YHUgJl3mzs\njYfID+hxmQAXD2wFGe8D0pUQWvTUlz1tZs04JpictVk7TM5XgBWaQK6a/2Nc\nUgPeVD2wl3rQCqZpehRjeYu78kgg2x98yAJp9X923t7h6wKuclYQTdVAU+WY\ntLwc1fcIk1Fm0Dqa3Egee4RcCRK3oQlGOKyRED7WMFa3kD9u41pHdgXWqywI\nO76q48d1Tuuq2ZtxCX3nNDCoULmPQPgYTiFru94qs8Vr06dgIn6+2l0YB6hn\nhDZO5kqUp1FGZ1EkqTZxp0mkK15CD6rC7COn3ZyE4bqKMZybQ2toDMx374Lc\nn6Onf6Vtc3lcWBytq3VcpQ3nYteBpaL5av1E/T4UrDtUpnxBnS2DKh6/ljOR\nhgxa\r\n=oE2B\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC4XpVFkNoksRLza0045/OMohZn/cW4k/F7RXHauy47SAIgUN1LfYNxda1QOmnB5nu9QzHaoTXAqPSWE2oRODmC3LI="}],"size":212178,"noattachment":false,"key":"/@fastify/busboy/-/@fastify/busboy-1.0.0-next1.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-next1_1638224473463_0.9839171413937888"},"_hasShrinkwrap":false,"readme":"# busboy\n\n<div align=\"center\">\n\n[![Build Status](https://github.com/fastify/busboy/actions/workflows/ci.yml/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[![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('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('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('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":1638224473703,"_cnpm_publish_time":1638224473703,"dist-tags":{"latest":"3.2.5","next":"1.0.0-next2"}}