{"name":"meros","version":"1.0.0-beta.7","description":"A fast utility for reading streamed multipart responses.","keywords":["multipart","multipart mixed","fetch","utility","reader"],"repository":{"type":"git","url":"git+https://github.com/maraisr/meros.git"},"license":"MIT","author":{"name":"Marais Rossouw","email":"me@marais.dev","url":"https://marais.io"},"exports":{".":{"import":"./node/index.mjs","browser":"./browser/index.mjs","require":"./node/index.js"},"./node":{"import":"./node/index.mjs","require":"./node/index.js"},"./browser":{"import":"./browser/index.mjs","require":"./browser/index.js"}},"unpkg":"browser/index.min.js","browser":"browser/index.mjs","module":"node/index.mjs","main":"node/index.js","types":"index.d.ts","typesVersions":{"*":{"*":["./types/*"]}},"scripts":{"bench":"node -r ts-node/register bench/index.ts","typecheck":"tsc --noEmit","build":"rollup -c","format":"prettier \"{*,.github/**/*}.+(json|yml|md)\" --write","prepublishOnly":"yarn build","test":"uvu -r ts-node/register -i mocks test"},"prettier":{"bracketSpacing":true,"printWidth":80,"proseWrap":"always","singleQuote":true,"tabWidth":4,"trailingComma":"all","useTabs":true},"devDependencies":{"@marais/tsconfig":"0.0.1","@rollup/plugin-node-resolve":"10.0.0","@types/benchmark":"2.1.0","@types/node":"14.14.7","benchmark":"2.1.4","fetch-multipart-graphql":"2.2.0","it-multipart":"1.0.5","prettier":"2.1.2","rollup":"2.33.1","rollup-plugin-terser":"7.0.2","rollup-plugin-typescript2":"0.29.0","ts-node":"9.0.0","typescript":"4.0.5","uvu":"0.4.1"},"volta":{"node":"15.2.0","yarn":"1.22.5"},"readme":"# `meros` &middot; <small>From Ancient Greek μέρος (méros, \"part\").</small>\n\n[![CI](https://img.shields.io/github/workflow/status/maraisr/meros/CI/main)](https://github.com/maraisr/meros/actions?query=workflow:CI+branch:main)\n[![codecov](https://img.shields.io/codecov/c/gh/maraisr/meros/main?token=dAoRt2GoQn)](https://codecov.io/gh/maraisr/meros)\n\n> A fast (761B) utility for reading streamed multipart/mixed responses.\n\n## ⚡ Features\n\n-   No dependencies\n-   Super [performant](#-benchmark)\n-   Supports _any_<sup>1</sup> `content-type`\n-   Supports `content-length`<sup>2</sup>\n-   _preamble_ and _epilogue_ don't yield\n-   Browser-Compatible\n-   Plugs into existing libraries like Relay and rxjs\n\n## ⚙️ Install\n\n```sh\nyarn add meros\n```\n\n## 🚀 Usage\n\n```ts\n// Rely on bundler/environment dection\nimport { meros } from 'meros';\n\nconst parts = await fetch('/fetch-multipart').then(meros);\n\n// As a simple Async Generator\nfor await (const part of parts) {\n\t// Do something with this part\n}\n\n// Used with rxjs streams\nfrom(parts).pipe(\n\ttap((part) => {\n\t\t// Do something with it\n\t}),\n);\n```\n\n## _Specific Environment_\n\n```ts\n// Browser\nimport { meros } from 'meros/browser';\n// import { meros } from 'https://cdn.skypack.dev/meros';\n\nconst parts = await fetch('/fetch-multipart').then(meros);\n\n// Node\nimport http from 'http';\nimport { meros } from 'meros/node';\n\nconst response = await new Promise((resolve) => {\n\tconst request = http.get(`http://my-domain/mock-ep`, (response) => {\n\t\tresolve(response);\n\t});\n\trequest.end();\n});\n\nconst parts = await meros(response);\n```\n\n## 🎒 Notes\n\nThis library aims to implement [RFC1341] in its entirety, however we aren't\nthere yet. That being said, you may very well use this library in other\nscenarios like streaming in file form uploads.\n\nPlease note; be sure to define a boundary that can be guaranteed to never\ncollide with things from the body:\n\n> _Because encapsulation boundaries must not appear in the body parts being\n> encapsulated, a user agent must exercise care to choose a unique boundary._\n>\n> <small>~ [RFC1341] 7.2.1</small>\n\n### _Caveats_\n\n-   No support the `/alternative` , `/digest` _or_ `/parallel` subtype at this\n    time.\n-   No support for\n    [nested multiparts](https://tools.ietf.org/html/rfc1341#appendix-C)\n\n## 🔎 API\n\n### _Browser_\n\n```ts\nfunction meros<T = object>(\n\tresponse: Response,\n): Promise<\n\t| Response\n\t| AsyncGenerator<\n\t\t\t| { json: true; headers: Record<string, string>; body: T }\n\t\t\t| { json: false; headers: Record<string, string>; body: string }\n\t  >\n>;\n```\n\n### _Node_\n\n```ts\nfunction meros<T = object>(\n\tresponse: IncomingMessage,\n): Promise<\n\t| IncomingMessage\n\t| AsyncGenerator<\n\t\t\t| { json: true; headers: Record<string, string>; body: T }\n\t\t\t| { json: false; headers: Record<string, string>; body: Buffer }\n\t  >\n>;\n```\n\nReturns an async generator that yields on every part. Worth noting that if\nmultiple parts are present in one chunk, each part will yield independently.\n\n> If the `content-type` is **NOT** a multipart, then it will resolve with the\n> response argument.\n\n<details>\n<summary>Example on how to handle this case</summary>\n\n```ts\nimport { meros } from 'meros';\n\nconst response = await fetch('/fetch-multipart'); // Assume this returns json\nconst parts = await meros(response);\n\nif (parts[Symbol.asyncIterator] < 'u') {\n\tfor await (const part of parts) {\n\t\t// Do something with this part\n\t}\n} else {\n\tconst data = await parts.json();\n}\n```\n\n</details>\n\n## 💨 Benchmark\n\n```\nValidation :: node\n✔ meros\n✘ it-multipart (FAILED @ \"should match reference patch set\")\n\nBenchmark :: node\n  meros                     x 27,045 ops/sec ±0.94% (81 runs sampled)\n  it-multipart              x 14,840 ops/sec ±0.93% (81 runs sampled)\n\nValidation :: browser\n✔ meros\n✘ fetch-multipart-graphql (FAILED @ \"should match reference patch set\")\n\nBenchmark :: browser\n  meros                     x 29,548 ops/sec ±0.56% (76 runs sampled)\n  fetch-multipart-graphql   x 13,613 ops/sec ±0.54% (78 runs sampled)\n```\n\n> Ran with Node v15.1.0\n\n## ❤ Thanks\n\nSpecial thanks to [Luke Edwards](https://github.com/lukeed) for performance\nguidance and high level api design.\n\n## License\n\nMIT © [Marais Rossouw](https://marais.io)\n\n<details>\n<summary>Footnote</summary>\n\n> 1: By default, we'll look for JSON, and parse that for you. If not, we'll give\n> you the body as what was streamed.</small>\n>\n> 2: If not given, everything from the body through boundary will yield\n\n</details>\n\n[rfc1341]: https://tools.ietf.org/html/rfc1341 'The Multipart Content-Type'\n","readmeFilename":"readme.md","gitHead":"b08eb7c0a79d4152e30596d62e5080c6561ac01f","bugs":{"url":"https://github.com/maraisr/meros/issues"},"homepage":"https://github.com/maraisr/meros#readme","_id":"meros@1.0.0-beta.7","_nodeVersion":"15.2.0","_npmVersion":"7.0.8","dist":{"integrity":"sha512-5iRlhVIj6bfFamljJMecZYuM+BTQqZvNONpBFjYqks3dj7O+7aLgDULKmqtH4kS6Tp22pjZ9qY63s5jrn247LA==","shasum":"f504799db624dc68150d3c2dbe509fad02246013","tarball":"http://registry-npm.ywwl.com/meros/download/meros-1.0.0-beta.7.tgz","fileCount":13,"unpackedSize":27634,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfryeuCRA9TVsSAnZWagAAXLAQAI2WgLNhaVH9di5l4P36\nHTQ1VdnY1Rrhmm3ajYjqKLpSJ+FrhAh/D8kccKQ5yUOgnoXZDTlfhWYarkel\nwKwvlqSBy4vkg0HQv36r+RRqmVzqOv6cfG9ioWU7YxM4NHjRs7Ff+n6JGCPy\nqh0Ypua8N1i/L7bT6oLdThKynJdojNI7SlCS7c6pJLcf1Q0DS6FlzwjOVxlo\n/bZTndmNP+30k8HErTRCEI+MZb2KitpQroOldOU6sn/KWkDK7lZoQRCuhuaN\n5M6TMut3UFOOc8NrgCyZFE5KBrng/B5zdoT7e0gJgAqjv8KW81M8WJPw4S2E\nAO2jTaWbJ6FpgyNiWviXtoeZbN1sY5waCzVj3odVTEgvvFtt9vIrOwcVV1P3\npmGCwRtAiOwjWbaghihqh0DlpxAv+u/XZUMOxO4fn6Jy5/5PpCMzS+U2Clxj\nvuQyur4luGezX7UQenMm2SVt7HG82lg+/ALobs65E9roHceIq6b0CbfjUWhV\nTyPrrG1O0WP3MbNuD5UgrN0KOZTCv/0FHrEwtHvh+C2sUuB/Vhm4wqbK7OpC\n7vMvHRqjhXZeQ92nllJYH03rygOiPE0Rhqkw/HVtzRf2pKGWb1T9WZEamyW/\nbTFn4sc6aJ4sTRXwSlU554izN0Fw5t07mJy0XwdQia4q5t+0VS4gvLNhUdMw\nDfzV\r\n=HevD\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICQ9E6q+acnIe2FwoMVsrXzw783b1AEm7e/CJFFdfJ9QAiEA2EaBHqtmpN4i9EVLNMIqu77o1XTlIfiq9t3CzrW5ypo="}],"size":6380,"noattachment":false,"key":"/meros/-/meros-1.0.0-beta.7.tgz"},"_npmUser":{"name":"marais","email":"me@maraisr.com"},"directories":{},"maintainers":[{"name":"marais","email":"me@maraisr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/meros_1.0.0-beta.7_1605314477701_0.2978349582346622"},"_hasShrinkwrap":false,"publish_time":1605314477849,"_cnpm_publish_time":1605314477849,"dist-tags":{"beta":"1.1.0-beta.2","latest":"1.3.2","next":"1.2.0-next.4"}}