{"name":"formstream","version":"1.5.1","description":"A multipart/form-data encoded stream, helper for file upload.","main":"lib/formstream.js","types":"types/formstream.d.ts","scripts":{"test":"egg-bin test","cov":"egg-bin cov","ci":"npm run lint && npm run tsd && npm run cov && NODE_DEBUG=formstream npm run cov","lint":"jshint .","tsd":"tsd","contributor":"git-contributor"},"repository":{"type":"git","url":"git://github.com/node-modules/formstream.git"},"keywords":["form","stream","multipart","form-data","upload","postfile","request"],"dependencies":{"destroy":"^1.0.4","mime":"^2.5.2","node-hex":"^1.0.1","pause-stream":"~0.0.11"},"devDependencies":{"@types/node":"^20.4.3","connect-multiparty":"1","egg-bin":"^5.6.1","express":"^4.16.4","git-contributor":"^2.1.5","jshint":"^2.13.6","pedding":"1","should":"4","tsd":"^0.28.1","urllib":"2"},"author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"https://github.com/fengmk2"},"license":"MIT","_id":"formstream@1.5.1","gitHead":"38b26233bdd16abff6bfe654c5037f89408aff31","bugs":{"url":"https://github.com/node-modules/formstream/issues"},"homepage":"https://github.com/node-modules/formstream#readme","_nodeVersion":"18.20.3","_npmVersion":"10.7.0","dist":{"integrity":"sha512-q7ORzFqotpwn3Y/GBK2lK7PjtZZwJHz9QE9Phv8zb5IrL9ftGLyi2zjGURON3voK8TaZ+mqJKERYN4lrHYTkUQ==","shasum":"b25f8121aa434cc82e8b36cdd765338b7b8df4de","tarball":"http://registry-npm.ywwl.com/formstream/download/formstream-1.5.1.tgz","fileCount":5,"unpackedSize":22128,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/formstream@1.5.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBtnozKXPcu6VAImpEnGCSyMJt3msOfdjwVplyozR4FiAiEA/TY4Ivv/ftu0do9gCws9fPxBMj26Zndb6TcjgIDa8D8="}],"size":6561,"noattachment":false,"key":"/formstream/-/formstream-1.5.1.tgz"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"directories":{},"maintainers":[{"name":"dead_horse","email":"dead_horse@qq.com"},{"name":"fengmk2","email":"fengmk2@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/formstream_1.5.1_1717737786896_0.865734769984037"},"_hasShrinkwrap":false,"readme":"# formstream\n\n[![NPM version][npm-image]][npm-url]\n[![CI](https://github.com/node-modules/formstream/actions/workflows/ci.yml/badge.svg)](https://github.com/node-modules/formstream/actions/workflows/ci.yml)\n[![Test coverage][codecov-image]][codecov-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/formstream.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/formstream\n[codecov-image]: https://codecov.io/github/node-modules/formstream/coverage.svg?branch=master\n[codecov-url]: https://codecov.io/github/node-modules/formstream?branch=master\n[download-image]: https://img.shields.io/npm/dm/formstream.svg?style=flat-square\n[download-url]: https://npmjs.org/package/formstream\n\nA [multipart/form-data](http://tools.ietf.org/html/rfc2388) encoded stream, helper for file upload.\n\n## Install\n\n```bash\nnpm install formstream\n```\n\n## Quick Start\n\n```js\nvar formstream = require('formstream');\nvar http = require('http');\n\nvar form = formstream();\n\n// form.file('file', filepath, filename);\nform.file('file', './logo.png', 'upload-logo.png');\n\n// other form fields\nform.field('foo', 'fengmk2').field('love', 'aerdeng');\n\n// even send file content buffer directly\n// form.buffer(name, buffer, filename, mimeType)\nform.buffer('file2', new Buffer('This is file2 content.'), 'foo.txt');\n\nvar options = {\n  method: 'POST',\n  host: 'upload.cnodejs.net',\n  path: '/store',\n  headers: form.headers()\n};\nvar req = http.request(options, function (res) {\n  console.log('Status: %s', res.statusCode);\n  res.on('data', function (data) {\n    console.log(data.toString());\n  });\n});\n\nform.pipe(req);\n```\n\n### Chaining\n\n```js\nvar fs = require('fs');\nvar formstream = require('formstream');\n\nvar filepath = './logo.png';\nfs.stat(filepath, function (err, stat) {\n  formstream()\n    .field('status', 'share picture')\n    .field('access_token', 'your access token')\n    .file('pic', filepath, 'logo.png', stat.size)\n    .pipe(process.stdout); // your request stream\n});\n```\n\n### Set min chunk buffer size\n\nSome web servers have a limit on the number of chunks, and you can set `minChunkSize` to ensure the size of chunk sent to the server.\n\n```js\nvar fs = require('fs');\nvar FormStream = require('formstream');\n\nvar filepath = './big-file.zip';\nfs.stat(filepath, function (err, stat) {\n  new FormStream({\n    // send >= 2MB chunk buffer size to the server\n    minChunkSize: 1024 * 1024 * 2,\n  }).field('status', 'share file')\n    .field('access_token', 'your access token')\n    .file('file', filepath, 'big-file.zip', stat.size)\n    .pipe(process.stdout); // your request stream\n});\n```\n\n## API Doc\n\n### formstream([options])\n\nCreate a form instance.\n\n#### Arguments\n\n- **options.minChunkSize** Number - min chunk size to emit data event\n\n#### Returns\n\nForm - form instance\n\n### FormStream#field(name, value)\n\nAdd a normal field to the form.\n\n#### Arguments\n\n- **name** String - Name of field\n- **value** String - Value of field\n\n#### Returns\n\nForm - form instance\n\n### FormStream#file(name, filepath[, filename][, filesize])\n\nAdd a local file to be uploaded to the form.\n\n#### Arguments\n\n- **name** String - Name of file field\n- **filepath** String - Local path of the file to be uploaded\n- ***filename*** String - Optional. Name of the file (will be the base name of `filepath` if empty)\n- ***filesize*** Number - Optional. Size of the file (will not generate `Content-Length` header if not specified)\n\n#### Returns\n\nForm - form instance\n\n### FormStream#buffer(name, buffer, filename[, contentType])\n\nAdd a buffer as a file to upload.\n\n#### Arguments\n\n- **name** String - Name of field\n- **buffer** Buffer - The buffer to be uploaded\n- **filename** String - The file name that tells the remote server\n- ***contentType*** String - Optional. Content-Type (aka. MIME Type) of content (will be infered with `filename` if empty)\n\n#### Returns\n\nForm - form instance\n\n### FormStream#stream(name, stream, filename[, contentType][, size])\n\nAdd a readable stream as a file to upload. Event 'error' will be emitted if an error occured.\n\n#### Arguments\n\n- **name** String - Name of field\n- **stream** [stream.Readable](http://nodejs.org/api/stream.html#stream_class_stream_readable) - A readable stream to be piped\n- **filename** String - The file name that tells the remote server\n- ***contentType*** String - Optional. Content-Type (aka. MIME Type) of content (will be infered with `filename` if empty)\n- ***size*** Number - Optional. Size of the stream (will not generate `Content-Length` header if not specified)\n\n#### Returns\n\nForm - form instance\n\n### FormStream#headers([headers])\n\nGet headers for the request.\n\n#### Arguments\n\n- **headers** Object - Additional headers\n\n#### Example\n\n```js\nvar headers = form.headers({\n  'Authorization': 'Bearer kei2akc92jmznvnkeh09sknzdk',\n  'Accept': 'application/vnd.github.v3.full+json'\n});\n```\n\n#### Returns\n\nObject - Headers to be sent.\n\n### Event 'error'\n\nEmitted if there was an error receiving data.\n\n### Event 'data'\n\nThe 'data' event emits when a Buffer was used.\n\nSee [Node.js Documentation](http://nodejs.org/api/stream.html#stream_event_data) for more.\n\n### Event 'end'\n\nEmitted when the stream has received no more 'data' events will happen.\n\nSee [Node.js Documentation](http://nodejs.org/api/stream.html#stream_event_end) for more.\n\n## License\n\n[MIT](LICENSE)\n\n<!-- GITCONTRIBUTOR_START -->\n\n## Contributors\n\n|[<img src=\"https://avatars.githubusercontent.com/u/156269?v=4\" width=\"100px;\"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/288288?v=4\" width=\"100px;\"/><br/><sub><b>xingrz</b></sub>](https://github.com/xingrz)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/32174276?v=4\" width=\"100px;\"/><br/><sub><b>semantic-release-bot</b></sub>](https://github.com/semantic-release-bot)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/13151189?v=4\" width=\"100px;\"/><br/><sub><b>fjc0k</b></sub>](https://github.com/fjc0k)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/18096247?v=4\" width=\"100px;\"/><br/><sub><b>mrspeiser</b></sub>](https://github.com/mrspeiser)<br/>|[<img src=\"https://avatars.githubusercontent.com/u/985607?v=4\" width=\"100px;\"/><br/><sub><b>dead-horse</b></sub>](https://github.com/dead-horse)<br/>|\n| :---: | :---: | :---: | :---: | :---: | :---: |\n[<img src=\"https://avatars.githubusercontent.com/u/7326406?v=4\" width=\"100px;\"/><br/><sub><b>shaozj</b></sub>](https://github.com/shaozj)<br/>\n\nThis project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Wed May 15 2024 00:34:12 GMT+0800`.\n\n<!-- GITCONTRIBUTOR_END -->\n","publish_time":1717737787066,"_cnpm_publish_time":1717737787066,"dist-tags":{"latest":"1.5.3"}}