{"name":"formstream","version":"0.0.6","keywords":["form","stream","multipart","form-data","upload","postfile","request"],"author":{"url":"http://fengmk2.github.com","name":"fengmk2","email":"fengmk2@gmail.com"},"license":"MIT","_id":"formstream@0.0.6","maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"}],"bugs":{"url":"https://github.com/fengmk2/formstream/issues"},"dist":{"shasum":"4475600d4fe40379202aed21039ef810d9ea1488","tarball":"http://registry-npm.ywwl.com/formstream/download/formstream-0.0.6.tgz","integrity":"sha512-31841MUaHnHBh2DKtS4B+egz51Hbb88vxkPZWB9567VsPpRwWiyia3p4YSIv8RMkD7A0ULT2T2f3YQNm5IDYEQ==","signatures":[{"sig":"MEQCIEznHgrMeygomWa4biUB+w9sa1Kot5iCkQgDpdipDEtZAiAwR9URxF29sXu4KiS/L/5wFEWeMtxA84cYR8Wl1vky8Q==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"size":5162,"noattachment":false,"key":"/formstream/-/formstream-0.0.6.tgz"},"main":"index.js","_from":".","scripts":{"test":"make test-all"},"_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"repository":{"url":"git://github.com/fengmk2/formstream.git","type":"git"},"_npmVersion":"1.3.2","description":"A multipart/form-data encoded stream, helper for file upload.","directories":{},"dependencies":{"mime":"1.2.9","pause-stream":">=0.0.10","buffer-concat":"0.0.1"},"devDependencies":{"mocha":"*","should":"*","blanket":"*","connect":"*","pedding":"*","coveralls":"*","travis-cov":"*","mocha-lcov-reporter":"*"},"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":1373854737861,"_cnpm_publish_time":1373854737861,"dist-tags":{"latest":"1.5.3"}}