{"name":"formidable","version":"2.0.0-canary.20200129.4","license":"MIT","description":"A node.js module for parsing form data, especially file uploads.","homepage":"https://github.com/node-formidable/node-formidable","funding":"https://ko-fi.com/tunnckoCore/commissions","repository":{"type":"git","url":"git+https://github.com/node-formidable/node-formidable.git"},"main":"./src/index.js","publishConfig":{"access":"public","tag":"canary"},"scripts":{"cleanup":"rm -rf test/tmp","lint":"eslint . --cache --fix --quiet --format codeframe","pretest":"yarn run cleanup","test":"mkdir test/tmp && node test/run.js"},"devDependencies":{"@tunnckocore/prettier-config":"^1.2.0","eslint":"^6.8.0","eslint-config-airbnb-base":"^14.0.0","eslint-config-prettier":"^6.10.0","eslint-plugin-import":"^2.20.0","eslint-plugin-prettier":"^3.1.2","prettier":"^1.19.1","prettier-plugin-pkgjson":"^0.2.0","request":"^2.11.4","urun":"^0.0.6","utest":"^0.0.8"},"readme":"<p align=\"center\">\n  <img alt=\"node formidable logo\" src=\"./logo.png\" />\n</p>\n\n# formidable\n\n> A Node.js module for parsing form data, especially file uploads.\n\n[![Code style][codestyle-img]][codestyle-url]\n[![npm version][npmv-img]][npmv-url]\n[![build status][build-img]][build-url]\n[![chat on gitter][chat-img]][chat-url]\n[![MIT license][license-img]][license-url]\n\n## Status: Maintained\n\nThis module was initially developed by [**@felixge**](https://github.com/felixge) for [Transloadit](http://transloadit.com/), a service focused on uploading and encoding images and videos. It has been battle-tested against hundreds of GBs of file uploads from a large variety of clients and is considered production-ready and is used in production for years.\n\nCurrently, we are few maintainers trying to deal with it. :) More contributors are always welcome! :heart:\nJump on [issue #412](https://github.com/felixge/node-formidable/issues/412) if you are interested.\n\n_**Note:** Master is a \"development\" branch - try it with `npm i formidable@canary`.\nDo not expect (for now) things from it to be inside the`latest`\"dist-tag\" in the Npm.\nThe`formidable@latest`is the`v1.2.1` version and probably it will be the last`v1` release!_\n\n_**Note: v2 is coming soon!**_\n\n## Highlights\n\n- Fast (~900-2500 mb/sec), streaming multipart parser\n- Automatically writing file uploads to disk\n- Low memory footprint\n- Graceful error handling\n- Very high test coverage\n\n## Install\n\n```sh\nnpm install formidable\n# or the development version\nnpm install formidable@canary\n```\n\nor with Yarn v1/v2\n\n```sh\nyarn add formidable\n# or the development version\nyarn add formidable@canary\n```\n\nThis is a low-level package, and if you're using a high-level framework it may already be included.\n\nHowever, [Express v4](http://expressjs.com) does not include any multipart handling, nor does [body-parser](https://github.com/expressjs/body-parser).\n\nFor `koa` there is [koa-better-body](https://ghub.now.sh/koa-better-body)\nwhich can handle ANY type of body / form-data - JSON, urlencoded, multpart and so on.\nA new major release is coming there too.\n\n## Example\n\nParse an incoming file upload.\n\n```js\nconst http = require('http');\nconst util = require('util');\nconst formidable = require('formidable');\n\nhttp\n  .createServer((req, res) => {\n    if (req.url === '/upload' && req.method.toLowerCase() === 'post') {\n      // parse a file upload\n      const form = formidable();\n\n      form.parse(req, (err, fields, files) => {\n        res.writeHead(200, { 'content-type': 'text/plain' });\n        res.write('received upload:\\n\\n');\n        res.end(util.inspect({ fields: fields, files: files }));\n      });\n\n      return;\n    }\n\n    // show a file upload form\n    res.writeHead(200, { 'content-type': 'text/html' });\n    res.end(`\n      <form action=\"/upload\" enctype=\"multipart/form-data\" method=\"post\">\n        <input type=\"text\" name=\"title\" /><br/>\n        <input type=\"file\" name=\"upload\" multiple=\"multiple\" /><br/>\n        <input type=\"submit\" value=\"Upload\" />\n      </form>\n    `);\n  })\n  .listen(8080, () => {\n    console.log('Server listening on http://localhost:8080/ ...');\n  });\n```\n\n## Benchmarks\n\nThe benchmark is quite old, from the old codebase. But maybe quite true though.\nPreviously the numbers was around ~500 mb/sec. Currently with moving to\nthe new Node.js Streams API it's faster. You can clearly see the differences\nbetween the Node versions.\n\n_Note: a lot better benchmarking could and should be done in future._\n\nBenchmarked on 8GB RAM, Xeon X3440 (2.53 GHz, 4 cores, 8 threads)\n\n```\n~/github/node-formidable master\n❯ nve --parallel 8 10 12 13 node benchmark/bench-multipart-parser.js\n\n ⬢  Node 8\n\n1261.08 mb/sec\n\n ⬢  Node 10\n\n1113.04 mb/sec\n\n ⬢  Node 12\n\n2107.00 mb/sec\n\n ⬢  Node 13\n\n2566.42 mb/sec\n```\n\n![benchmark January 29th, 2020](./benchmark/2020-01-29_xeon-x3440.png)\n\n## API\n\n### Formidable / IncomingForm\n\nAll shown are equivalent.\n\n_Please pass [`options`](#options) to the function/constructor,\nnot by passing assigning them to the instance `form`_\n\n```js\nconst formidable = require('formidable');\nconst form = formidable(options);\n\n// or\nconst { formidable } = require('formidable');\nconst form = formidable(options);\n\n// or\nconst { IncomingForm } = require('formidable');\nconst form = new IncomingForm(options);\n\n// or\nconst { Formidable } = require('formidable');\nconst form = new Formidable(options);\n```\n\n### Options\n\nSee it's defaults in [src/Formidable.js](./src/Formidable.js#L14-L22) (the `DEFAULT_OPTIONS` constant).\n\n- `options.encoding` **{string}** - default `'utf-8'`; sets encoding for incoming form fields,\n- `options.uploadDir` **{string}** - default `os.tmpdir()`; the directory for placing file uploads in. You can move them later by using `fs.rename()`\n- `options.keepExtensions` **{boolean}** - default `false`; to include the extensions of the original files or not\n- `options.maxFieldsSize` **{number}** - default `20 * 1024 * 1024` (20mb); limit the amount of memory all fields together (except files) can allocate in bytes.\n- `options.maxFieldsSize` **{number}** - default `200 * 1024 * 1024` (200mb); limit the size of uploaded file.\n- `options.maxFields` **{number}** - default `1000`; limit the number of fields that the Querystring parser will decode, set 0 for unlimited\n- `options.hash` **{boolean}** - default `false`; include checksums calculated for incoming files, set this to some hash algorithm, see [crypto.createHash](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options) for available algorithms\n- `options.multiples` **{boolean}** - default `false`; when you call the `.parse` method, the `files` argument (of the callback) will contain arrays of files for inputs which submit multiple files using the HTML5 `multiple` attribute. Also, the `fields` argument will contain arrays of values for fields that have names ending with '[]'.\n\n_**Note:** If this value is exceeded, an `'error'` event is emitted._\n\n```js\n// The amount of bytes received for this form so far.\nform.bytesReceived;\n```\n\n```js\n// The expected number of bytes in this form.\nform.bytesExpected;\n```\n\n### .parse(request, callback)\n\nParses an incoming Node.js `request` containing form data.\nIf `callback` is provided, all fields and files are collected and passed to the callback.\n\n```js\nconst formidable = require('formidable');\n\nconst form = formidable({ multiples: true, uploadDir: __dirname });\n\nform.parse(req, (err, fields, files) => {\n  console.log('fields:', fields);\n  console.log('files:', files);\n});\n```\n\nYou may overwrite this method if you are interested in directly accessing the multipart stream. Doing so will disable any `'field'` / `'file'` events processing which would occur otherwise, making you fully responsible for handling the processing.\n\nIn the example below, we listen on couple of events and direct them to the `data` listener,\nso you can do whatever you choose there, based on whether its before the file been emitted,\nthe header value, the header name, on field, on file and etc.\n\nOr the other way could be to just override the `form.onPart` as it's shown a bit later.\n\n```js\nform.once('error', console.error);\n\nform.on('fileBegin', (filename, file) => {\n  form.emit('data', { name: 'fileBegin', filename, value: file });\n});\n\nform.on('file', (filename, file) => {\n  form.emit('data', { name: 'file', key: filename, value: file });\n});\n\nform.on('field', (fieldName, fieldValue) => {\n  form.emit('data', { name: 'field', key: fieldName, value: fieldValue });\n});\n\nform.once('end', () => {\n  console.log('Done!');\n});\n\n// If you want to customize whatever you want...\nform.on('data', ({ name, key, value, buffer, start, end, ...more }) => {\n  if (name === 'partBegin') {\n  }\n  if (name === 'partData') {\n  }\n  if (name === 'headerField') {\n  }\n  if (name === 'headerValue') {\n  }\n  if (name === 'headerEnd') {\n  }\n  if (name === 'headersEnd') {\n  }\n  if (name === 'field') {\n    console.log('field name:', key);\n    console.log('field value:', value);\n  }\n  if (name === 'file') {\n    console.log('file:', key, value);\n  }\n  if (name === 'fileBegin') {\n    console.log('fileBegin:', key, value);\n  }\n});\n```\n\n### form.onPart\n\nIf you want to use Formidable to only handle certain parts for you, you can do something similar.\nOr see [#387](https://github.com/node-formidable/node-formidable/issues/387) for inspiration,\nyou can for example validate the mime-type.\n\n```js\nconst form = formidable();\n\nform.onPart = (part) => {\n  part.on('data', (buffer) {\n    // do whatever you want here\n  });\n};\n```\n\nFor example, force Formidable to be used only on non-file \"parts\" (i.e., html fields)\n\n```js\nconst form = formidable();\n\nform.onPart = function(part) {\n  // let formidable handle only non-file parts\n  if (part.filename === '' || !part.mime) {\n    // used internally, please do not override!\n    form.handlePart(part);\n  }\n};\n```\n\n### File\n\n```ts\nexport interface File {\n  // The size of the uploaded file in bytes.\n  // If the file is still being uploaded (see `'fileBegin'` event),\n  // this property says how many bytes of the file have been written to disk yet.\n  file.size: number;\n\n  // The path this file is being written to. You can modify this in the `'fileBegin'` event in\n  // case you are unhappy with the way formidable generates a temporary path for your files.\n  file.path: string;\n\n  // The name this file had according to the uploading client.\n  file.name: string | null;\n\n  // The mime type of this file, according to the uploading client.\n  file.type: string | null;\n\n  // A Date object (or `null`) containing the time this file was last written to.\n  // Mostly here for compatibility with the [W3C File API Draft](http://dev.w3.org/2006/webapi/FileAPI/).\n  file.lastModifiedDate: Date | null;\n\n  // If `options.hash` calculation was set, you can read the hex digest out of this var.\n  file.hash: string | 'sha1' | 'md5' | 'sha256' | null;\n}\n```\n\n#### file.toJSON()\n\nThis method returns a JSON-representation of the file, allowing you to\n`JSON.stringify()` the file which is useful for logging and responding\nto requests.\n\n### Events\n\n#### `'progress'`\n\nEmitted after each incoming chunk of data that has been parsed. Can be used to roll your own progress bar.\n\n```js\nform.on('progress', (bytesReceived, bytesExpected) => {});\n```\n\n#### `'field'`\n\nEmitted whenever a field / value pair has been received.\n\n```js\nform.on('field', (name, value) => {});\n```\n\n#### `'fileBegin'`\n\nEmitted whenever a new file is detected in the upload stream. Use this event if\nyou want to stream the file to somewhere else while buffering the upload on\nthe file system.\n\n```js\nform.on('fileBegin', (name, file) => {});\n```\n\n#### `'file'`\n\nEmitted whenever a field / file pair has been received. `file` is an instance of `File`.\n\n```js\nform.on('file', (name, file) => {});\n```\n\n#### `'error'`\n\nEmitted when there is an error processing the incoming form. A request that experiences an error is automatically paused, you will have to manually call `request.resume()` if you want the request to continue firing `'data'` events.\n\n```js\nform.on('error', (err) => {});\n```\n\n#### `'aborted'`\n\nEmitted when the request was aborted by the user. Right now this can be due to a 'timeout' or 'close' event on the socket. After this event is emitted, an `error` event will follow. In the future there will be a separate 'timeout' event (needs a change in the node core).\n\n```js\nform.on('aborted', () => {});\n```\n\n#### `'end'`\n\nEmitted when the entire request has been received, and all contained files have finished flushing to disk. This is a great place for you to send your response.\n\n```js\nform.on('end', () => {});\n```\n\n## License\n\nFormidable is licensed under the [MIT License][license-url].\n\n## Ports\n\n- [multipart-parser](http://github.com/FooBarWidget/multipart-parser): a C++ parser based on formidable\n\n## Credits\n\n- [Ryan Dahl](http://twitter.com/ryah) for his work on [http-parser](http://github.com/ry/http-parser) which heavily inspired multipart_parser.js\n\n<!-- badges -->\n\n[codestyle-url]: https://github.com/airbnb/javascript\n[codestyle-img]: https://badgen.net/badge/code%20style/airbnb%20%2B%20prettier/ff5a5f?icon=airbnb&cache=300\n[build-img]: https://badgen.net/travis/node-formidable/node-formidable/master?label=build&icon=travis\n[build-url]: https://travis-ci.org/node-formidable/node-formidable.svg?branch=master\n[npmv-img]: https://badgen.net/npm/v/formidable?icon=npm\n[npmv-url]: https://npmjs.com/package/formidable\n[license-img]: https://badgen.net/npm/license/formidable\n[license-url]: https://github.com/node-formidable/node-formidable/blob/master/LICENSE\n[chat-img]: https://badgen.net/badge/chat/on%20gitter/46BC99?icon=gitter\n[chat-url]: https://gitter.im/node-formidable/Lobby\n","readmeFilename":"README.md","gitHead":"8ea22e020b3ede2184c417de8592d052e288384c","bugs":{"url":"https://github.com/node-formidable/node-formidable/issues"},"_id":"formidable@2.0.0-canary.20200129.4","_nodeVersion":"12.14.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-9QIPQc48W8+PGg9r/1YxkXjKYpSXMC72LHwl8HEQGIVn7jxKi/n1cPI+DYJTn6ZUp/fTCc98wbLF0WMYk1GUXg==","shasum":"2099fcdba9347002275bd87c0e6e00e8a959a860","tarball":"http://registry-npm.ywwl.com/formidable/download/formidable-2.0.0-canary.20200129.4.tgz","fileCount":12,"unpackedSize":51325,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeMQ/TCRA9TVsSAnZWagAA3RsP/0uTnzMmARFeQX5W7BPv\nfhUoilwdNhtgrJIetKCXArnA/ZxrtjZREXxhuIm5nlXeLlywnOGghTXwKf1W\n7/dp7+a+yscASOeR3zImSvrWSn1mFgGLzYsbl0ItC4a8ulW9E+7QlwS/JS6Y\nuXBNgynunx9YazH+0xlCJO97XwNBwIMJL+SciAcu3Y7TJ2XtQIvAvoi8tBIs\nNfI2WZZzJ0/3RVyXIP6i5RVuzVu4Jm8HGfbqBbIzfG9FgLiId/d6ZBiBMuOs\nQ89lLD3YHPLDVY6crVOMzKODQdVi17rVx9b00IQ9xTTOkPwKSAAbZJdtc7/A\nyMz1dN7RQji5I1IuifE87fwsKjsBDiq+cJrESSj1QDSAyvVnrRpL+mWERuV5\ndrbsiyBBLD+w59Z4JYCsXSgbnsssoTA5lADiBH718ApYLBrRY1DKT9v2t2fS\nJcnZEpytu0Ywyhw2khhsqG4TRbQN5YWhGXCVjrftqe2EA5a2T3GyDTc08Acb\npfyDqP+ImrHrCm7JtNkPUdz73T1pnS1cXoE7LNAK2vWBH5HMSkZnCJxUOBYR\n7XYFzpTeaucHHT7Y3/PAkKAZQpk/+6ZyLTCvVh/wi2V28FX/2fFXy36CBzVd\nsSIj8t0p0RfvexcDSBV4n/+OXfE4UYTOU9GKuNtPE9ngtbIrJ7jWicweKpMy\n4eVC\r\n=+ejB\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHpvCnQGlfh61g57k5o86cbHx5hJhfDfUGlmENeaIoLBAiAiSNQMnk7GYIivFUa82/wSmsI/jCGeif/8/XVqI1HXmA=="}],"size":15483,"noattachment":false,"key":"/formidable/-/formidable-2.0.0-canary.20200129.4.tgz"},"maintainers":[{"email":"chalkerx@gmail.com","name":"chalker"},{"email":"felix@debuggable.com","name":"felixge"},{"email":"npmspam@geekhood.net","name":"kornel"},{"email":"nathanael.dmc@outlook.fr","name":"quantumsheep"},{"email":"superjoe30@gmail.com","name":"superjoe"},{"email":"me@svenlito.com","name":"svnlto"},{"email":"tim@fostle.com","name":"tim-smart"},{"email":"mameto2011@gmail.com","name":"tunnckocore"},{"email":"super.ludiq@gmail.com","name":"vanchoy"},{"email":"xargs@disroot.org","name":"xargs"}],"_npmUser":{"name":"tunnckocore","email":"opensource@tunnckocore.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/formidable_2.0.0-canary.20200129.4_1580273619199_0.0764005023952623"},"_hasShrinkwrap":false,"deprecated":"Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau","publish_time":1580273619430,"_cnpm_publish_time":1580273619430,"dist-tags":{"latest":"3.5.4","legacy":"1.2.6","next":"4.0.0-rc.6","v1":"1.2.6","v2-latest":"2.1.5"}}