{"name":"formstream","version":"1.5.2","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"},"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","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.2","gitHead":"f6096dc85e7b9bc2362f6365bb63d64113de807c","bugs":{"url":"https://github.com/node-modules/formstream/issues"},"homepage":"https://github.com/node-modules/formstream#readme","_nodeVersion":"20.19.4","_npmVersion":"10.8.2","dist":{"integrity":"sha512-NASf0lgxC1AyKNXQIrXTEYkiX99LhCEXTkiGObXAkpBui86a4u8FjH1o2bGb3PpqI3kafC+yw4zWeK6l6VHTgg==","shasum":"81f282571665b8afd82e0df39399862cb2527c6d","tarball":"http://registry-npm.ywwl.com/formstream/download/formstream-1.5.2.tgz","fileCount":5,"unpackedSize":20799,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/formstream@1.5.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCWAbf94wBZMYbZfmpPiTMFAa+zXt5AQ5h9YQLl/1nSYAIgRDZAUpWEhslRfpb6pz4k1fCvS6svWr78F7dVXKuq1r4="}],"size":6188,"noattachment":false,"key":"/formstream/-/formstream-1.5.2.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-npm-production","tmp":"tmp/formstream_1.5.2_1753752527424_0.02484806833203157"},"_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## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=node-modules/formstream)](https://github.com/node-modules/formstream/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n","publish_time":1753752527606,"_cnpm_publish_time":1753752527606,"dist-tags":{"latest":"1.5.3"}}