{"_id":"multi-part-lite","_rev":"1-3be134bca9ccbcbfdc315dc7fd761495","name":"multi-part-lite","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"multi-part-lite","author":{"name":"Alexey Bystrov","email":"strikeentco@gmail.com"},"version":"1.0.0","engines":{"node":">=8.3.0"},"description":"Simple and fast multipart/form-data implementation without any dependencies. With Stream and Buffer modes. Supports: Strings, Numbers, Arrays, Streams, Buffers and Vinyl.","keywords":["multi-part","form","data","buffer","stream","vinyl","form-data","multipart"],"main":"./main.js","scripts":{"test":"mocha test","lint":"eslint main.js lib/**","check":"npm run lint && npm run test","cover":"nyc ./node_modules/mocha/bin/_mocha && nyc report --reporter=html","test-on-travis":"nyc ./node_modules/mocha/bin/_mocha && nyc report --reporter=lcovonly"},"repository":{"type":"git","url":"git+https://github.com/strikeentco/multi-part-lite.git"},"bugs":{"url":"https://github.com/strikeentco/multi-part-lite/issues"},"dependencies":{},"devDependencies":{"eslint":"^5.16.0","eslint-config-airbnb":"^17.1.1","eslint-plugin-import":"^2.18.2","eslint-plugin-jsx-a11y":"^6.2.3","eslint-plugin-react":"^7.14.3","express":"^4.17.1","got":"^9.6.0","mocha":"^6.2.0","multer":"^1.4.2","nyc":"^14.1.1","should":"^13.2.3","vinyl":"^2.2.0"},"license":"MIT","gitHead":"7fa944a00711211034d7a81747572f8f5074f9d2","homepage":"https://github.com/strikeentco/multi-part-lite#readme","_id":"multi-part-lite@1.0.0","_npmVersion":"6.5.0","_nodeVersion":"10.10.0","_npmUser":{"name":"strikeentco","email":"strikeentco@gmail.com"},"dist":{"integrity":"sha512-KxIRbBZZ45hoKX1ROD/19wJr0ql1bef1rE8Y1PCwD3PuNXV42pp7Wo8lEHYuAajoT4vfAFcd3rPjlkyEEyt1nw==","shasum":"7b86baf8ff83ef20ca13f1269a0f35aec42b9000","tarball":"https://registry.npmjs.org/multi-part-lite/-/multi-part-lite-1.0.0.tgz","fileCount":6,"unpackedSize":20186,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdUFDbCRA9TVsSAnZWagAApGAQAIbACJAqlCq7vo/sULIp\nZ5JahS8EqsrMq2jID66o9r79XJYFI4Sbu8B0ZRxpHqlwheRGmMAjQFOigi+y\nFB90794Ijc888fYpNKmUotkvqlnjOluPncX2qTZRtMgxiEU1ENrbo8CjmCRA\nqzdMfRHI44QKc0WBiU+W85cMuMr5+VSnQ0EllPXYU8JvJF6k82H21qw0GiQf\nyCaPTj7sewMoFtgurwRenWQcZLsjkq5krjjqjy7TnrtbkWtFS8Kqj+0bOsqC\nu7CVrdaVqWsv3511o3gUJIthdEtc/dX1n7+zJoqiIEBlQNg97QJSVG+e0mLC\n70tGF8E3pIKxfdY9UksQjUGaqnrh9tfEKvE+oLJSpWabdcknJtSVDDhgFJAK\nQlv3G4G2Z3Cz/5rZsCwm2iJXrmctYLoTDTCBHcoR4ZjjiOOOyRVWTR07rMFg\nzHhH/i7Vbugt5WLrdQpIGP7l8aLLQZzevzIeOunlBTylT4mCaqqwk5+RKoZq\n5p5lq4PSJ+IdqACfjlIyomubL7YyFkyuo8AdwwdmrY+qMP4Ao5z2GiX/04aX\n+Lnda0PPsMaeZ/9yPj/MQ0Kl3saZMqUOFxY796nEMLgUM7vfZfosVf9UaFmR\nj3OSU8VnXr4VqvmMbacEm301M1DQ4zHl+UFOUeBUoRrwO2xeBUfegGAUHalc\nxOu3\r\n=XEUS\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDgrwvfXzi2EKgWomRQdWeoQRK6sDVzubtqSfqivJIoaAIhANd6Jrg7K9Km0Jvyo1BCsNZ/nhOeetPsambx069bRdlg"}]},"maintainers":[{"name":"strikeentco","email":"strikeentco@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/multi-part-lite_1.0.0_1565544667163_0.6555596906073016"},"_hasShrinkwrap":false}},"time":{"created":"2019-08-11T17:31:07.162Z","1.0.0":"2019-08-11T17:31:07.323Z","modified":"2022-05-10T00:31:28.392Z"},"maintainers":[{"name":"strikeentco","email":"strikeentco@gmail.com"}],"description":"Simple and fast multipart/form-data implementation without any dependencies. With Stream and Buffer modes. Supports: Strings, Numbers, Arrays, Streams, Buffers and Vinyl.","homepage":"https://github.com/strikeentco/multi-part-lite#readme","keywords":["multi-part","form","data","buffer","stream","vinyl","form-data","multipart"],"repository":{"type":"git","url":"git+https://github.com/strikeentco/multi-part-lite.git"},"author":{"name":"Alexey Bystrov","email":"strikeentco@gmail.com"},"bugs":{"url":"https://github.com/strikeentco/multi-part-lite/issues"},"license":"MIT","readme":"multi-part-lite [![License](https://img.shields.io/npm/l/multi-part-lite.svg)](https://github.com/strikeentco/multi-part-lite/blob/master/LICENSE) [![npm](https://img.shields.io/npm/v/multi-part-lite.svg)](https://www.npmjs.com/package/multi-part-lite)\n==========\n[![Build Status](https://travis-ci.org/strikeentco/multi-part-lite.svg)](https://travis-ci.org/strikeentco/multi-part-lite) [![node](https://img.shields.io/node/v/multi-part-lite.svg)](https://www.npmjs.com/package/multi-part-lite) [![Test Coverage](https://api.codeclimate.com/v1/badges/3e14955aae296674c29e/test_coverage)](https://codeclimate.com/github/strikeentco/multi-part-lite/test_coverage)\n\nA `multi-part-lite` allows you to create multipart/form-data `Stream` and `Buffer`, which can be used to submit forms and file uploads to other web applications.\n\nThere are no external dependencies, so it as fast and simple as possible.\n\nSupports: `Strings`, `Numbers`, `Arrays`, `Streams`, `Buffers` and `Vinyl`.\n\n## Install\n```sh\n$ npm install multi-part-lite --save\n```\n\n## Usage\nUsage with `got` as `Stream`:\n\n```js\nconst got = require('got');\nconst Multipart = require('multi-part-lite');\nconst form = new Multipart();\n\nform.append('photo', got.stream('https://avatars1.githubusercontent.com/u/2401029'), { filename: 'image.jpg', contentType: 'image/jpeg' });\nform.append('field', 'multi-part test');\n\ngot.post('127.0.0.1:3000', { headers: form.getHeaders(), body: form.stream() });\n```\nUsage with `got` as `Buffer`:\n\n```js\nconst got = require('got');\nconst Multipart = require('multi-part-lite');\nconst form = new Multipart();\n\nform.append('photo', got.stream('https://avatars1.githubusercontent.com/u/2401029'), { filename: 'image.jpg', contentType: 'image/jpeg' });\nform.append('field', 'multi-part test');\n\n(async () => {\n  const body = await form.buffer();\n  got.post('127.0.0.1:3000', { headers: form.getHeaders(false), body });\n})()\n```\nUsage with `http`/`https` as `Stream`:\n\n```js\nconst http = require('http');\nconst https = require('https');\nconst Multipart = require('multi-part-lite');\nconst form = new Multipart();\n\nform.append('photo', https.request('https://avatars1.githubusercontent.com/u/2401029'), { filename: 'image.jpg', contentType: 'image/jpeg' });\n\nform.stream().pipe(http.request({ headers: form.getHeaders(), hostname: '127.0.0.1', port: 3000, method: 'POST' }));\n```\nUsage with `http`/`https` as `Buffer`:\n\n```js\nconst http = require('http');\nconst https = require('https');\nconst Multipart = require('multi-part-lite');\nconst form = new Multipart();\n\nform.append('photo', https.request('https://avatars1.githubusercontent.com/u/2401029'), { filename: 'image.jpg', contentType: 'image/jpeg' });\n\n(async () => {\n  const body = await form.buffer();\n  const req = http.request({ headers: form.getHeaders(false), hostname: '127.0.0.1', port: 3000, method: 'POST' });\n  req.end(body);\n})()\n```\n\n# API\n\n### new Multipart([options])\n\nConstructor.\n\n### Params:\n* **[options]** (*Object*) - `Object` with options:\n  * **[boundary]** (*String|Number*) - Custom boundary for `multipart` data. Ex: if equal `CustomBoundary`, boundary will be equal exactly `CustomBoundary`.\n  * **[boundaryPrefix]** (*String|Number*) - Custom boundary prefix for `multipart` data. Ex: if equal `CustomBoundary`, boundary will be equal something like `--CustomBoundary567689371204`.\n  * **[defaults]** (*Object*) - `Object` with defaults values:\n    * **[name]** (*String*) - File name which will be used, if `filename` is not specified in the options of `.append` method. By default `file`.\n    * **[ext]** (*String*) - File extension which will be used, if `filename` is not specified in the options of `.append` method. By default `bin`.\n    * **[type]** (*String*) - File content-type which will be used, if `contentType` is not specified in the options of `.append` method. By default `application/octet-stream`.\n\n### .append(name, value, [options])\n\nAdds a new data to the `multipart/form-data` stream.\n\n### Params:\n* **name** (*String|Number*) - Field name. Ex: `photo`.\n* **value** (*Mixed*) - Value can be `String`, `Number`, `Array`, `Buffer`, `ReadableStream` or even [Vynil](https://www.npmjs.com/package/vinyl).\n* **[options]** (*Object*) - Additional options:\n  * **filename**  (*String*) - File name. You should always specify file name with extension, otherwise `file.bin` will be set. Ex: `anonim.jpg`.\n  * **contentType** (*String*) - File content type. You should always specify content-type, otherwise `application/octet-stream` will be set. Ex: `image/jpeg`.\n\nIf `value` is an array, `append` will be called for each value:\n```js\nform.append('array', [0, [2, 3], 1]);\n\n// similar to\n\nform.append('array', 0);\nform.append('array', 2);\nform.append('array', 3);\nform.append('array', 1);\n```\n\n`Null`, `false` and `true` will be converted to `'0'`, `'0'` and `'1'`. Numbers will be converted to strings also.\n\n**Warning:** You must specify the correct `contentType` and `filename`. This library doesn't validate them. You can use [`multi-part`](https://github.com/strikeentco/multi-part) library which can handle it for you.\n\n### .stream()\n\nReturns a `multipart/form-data` stream.\n\n### .buffer()\n\nReturns a `Promise` with a buffer of the `multipart/form-data` stream data.\n\n### .getBoundary()\n\nReturns the form boundary used in the `multipart/form-data` stream.\n\n```js\nform.getBoundary(); // -> '--MultipartBoundary352840693617'\n```\n\n### .getLength()\n\nReturns the length of a buffer of the `multipart/form-data` stream data.\n\nShould be called after `.buffer()`;\n\nFor `.stream()` it's always `0`.\n\n```js\nawait form.buffer();\nform.getLength(); // -> 12345\n```\n\n### .getHeaders(chunked = true)\n\nReturns the headers.\n\nIf you want to get correct `content-length`, you should call it after `.buffer()`. There is no way to know `content-length` of the `.stream()`, so it will be always `0`.\n\n### Params:\n* **chunked** (*Boolean*) - If `false` - headers will include `content-length` header, otherwise there will be `transfer-encoding: 'chunked'`.\n\n```js\nform.getHeaders(); // ->\n//{\n//  'transfer-encoding': 'chunked',\n//  'content-type': 'multipart/form-data; boundary=\"--MultipartBoundary352840693617\"'\n//}\n```\nWith `.buffer()`:\n```js\nform.getHeaders(false); // ->\n//{\n//  'content-length': '0',\n//  'content-type': 'multipart/form-data; boundary=\"--MultipartBoundary352840693617\"'\n//}\n\nawait form.buffer();\nform.getHeaders(false); // ->\n//{\n//  'content-length': '12345',\n//  'content-type': 'multipart/form-data; boundary=\"--MultipartBoundary352840693617\"'\n//}\n```\n\n## License\n\nThe MIT License (MIT)<br/>\nCopyright (c) 2019 Alexey Bystrov\n","readmeFilename":"README.md"}