{"id":27979297,"url":"https://github.com/apeleghq/ts-multipart-parser","last_synced_at":"2025-05-08T02:51:56.942Z","repository":{"id":153079182,"uuid":"628087594","full_name":"ApelegHQ/ts-multipart-parser","owner":"ApelegHQ","description":"TypeScript streaming parser for MIME multipart messages","archived":false,"fork":false,"pushed_at":"2025-03-24T04:16:17.000Z","size":257,"stargazers_count":8,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-08T02:51:49.746Z","etag":null,"topics":["encoder","encoder-decoder","javascript","mime","mime-parser","multipart","parser","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ApelegHQ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-14T22:12:14.000Z","updated_at":"2025-03-24T04:15:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"c4f85717-25fb-45ca-b7ab-c8c88179b46c","html_url":"https://github.com/ApelegHQ/ts-multipart-parser","commit_stats":null,"previous_names":["apeleghq/ts-multipart-parser"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApelegHQ%2Fts-multipart-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApelegHQ%2Fts-multipart-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApelegHQ%2Fts-multipart-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApelegHQ%2Fts-multipart-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ApelegHQ","download_url":"https://codeload.github.com/ApelegHQ/ts-multipart-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252989941,"owners_count":21836666,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["encoder","encoder-decoder","javascript","mime","mime-parser","multipart","parser","typescript"],"created_at":"2025-05-08T02:51:56.542Z","updated_at":"2025-05-08T02:51:56.930Z","avatar_url":"https://github.com/ApelegHQ.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Multipart Message Parser\r\n\r\n [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=Exact-Realty_ts-multipart-parser\u0026metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=Exact-Realty_ts-multipart-parser)\r\n [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=Exact-Realty_ts-multipart-parser\u0026metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=Exact-Realty_ts-multipart-parser)\r\n [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=Exact-Realty_ts-multipart-parser\u0026metric=bugs)](https://sonarcloud.io/summary/new_code?id=Exact-Realty_ts-multipart-parser)\r\n [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=Exact-Realty_ts-multipart-parser\u0026metric=security_rating)](https://sonarcloud.io/summary/new_code?id=Exact-Realty_ts-multipart-parser)\r\n [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Exact-Realty_ts-multipart-parser\u0026metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=Exact-Realty_ts-multipart-parser)\r\n ![NPM Downloads](https://img.shields.io/npm/dw/@apeleghq/multipart-parser?style=flat-square)\r\n\r\nThis is a library for parsing MIME multipart messages, such as those used in\r\nHTTP requests and email messages, written in TypeScript. It provides an\r\neasy-to-use async generator that returns the parsed headers and body of each\r\npart in a multipart message. Nested multipart messages are supported.\r\n\r\n## Features\r\n\r\n  * Parses multipart messages according to the\r\n    [specification](https://www.ietf.org/rfc/rfc2046.html#section-5.1)\r\n  * Supports nested multipart messages\r\n  * Lightweight and fast\r\n  * Written in TypeScript, but can be used with plain JavaScript as well\r\n  * Well-tested\r\n\r\n## 🚀 Installation\r\n\r\nYou can install the library using either `npm` or `yarn`:\r\n\r\n```sh\r\nnpm install @apeleghq/multipart-parser\r\n```\r\n\r\n```sh\r\nyarn add @apeleghq/multipart-parser\r\n```\r\n\r\n## 🎬 Usage\r\n\r\nThe library exports the function `parseMultipartMessage`, which returns an async\r\ngenerator that yields objects with the headers and body (as a `Uint8Array`) of\r\neach part in the multipart message.\r\n\r\n### 📚 API\r\n\r\n#### `parseMultipartMessage(stream: ReadableStream, boundary: string): AsyncGenerator`\r\n\r\nThis function takes a `ReadableStream` and a boundary string as arguments, and\r\nreturns an asynchronous generator that yields objects with the following\r\nproperties:\r\n\r\n  * `headers`: a `Headers` object containing the headers of the current part\r\n  * `body`: a `Uint8Array` containing the body of the current part, or `null` if\r\n    the part is empty.\r\n  * `parts`: a nested iterator of the same structure for any parts within the\r\n    current part, if the part's `Content-Type` header indicates that it is a\r\nmultipart message.\r\n\r\n#### `boundaryRegex: RegExp`\r\n\r\nA regular expression that can be used to validate a boundary string.\r\n\r\n#### `boundaryMatchRegex: RegExp`\r\n\r\nA regular expression that can be used to extract a boundary string from a\r\n`Content-Type` header.\r\n\r\n#### `encodeMultipartMessage(boundary: string, msg: AsyncIterable\u003cTDecodedMultipartMessage\u003e): ReadableStream\u003cArrayBuffer\u003e`\r\n\r\nThis function takes a boundary string and an array of messages as arguments and returns a `ReadableStream` that can be read to obtain a multipart message.\r\n\r\n`TDecodedMultipartMessage` is defined as an object with the following fields:\r\n\r\n  * `headers`: a `Headers` object containing the headers of the current part\r\n  * `body` (optional): The body of the current part, or `null` if the part is\r\n     empty. It can be any of the following types: `ArrayBuffer`, `Blob`, `ReadableStream` or any typed array, such as `Uint8Array`.\r\n  * `parts` (optional): An async or sync iterable of one element or more of\r\n     the same type (`TDecodedMultipartMessage`), for nested messages. If both\r\n     `body` and `parts` are specified, `body` takes precedence.\r\n\r\n### Example\r\n\r\n```js\r\nimport { parseMultipartMessage } from '@apeleghq/multipart-message-parser';\r\n\r\nconst decoder = new TextDecoder();\r\n\r\nconst stream = ... // a ReadableStream containing the multipart message\r\nconst boundary = 'my-boundary'; // the boundary of the multipart message\r\n\r\nfor await (const part of parseMultipartMessage(stream, boundary)) {\r\n  console.log(part.headers.get('content-type'));\r\n  console.log(decoder.decode(part.body));\r\n}\r\n```\r\n\r\n## 🤝 Contributing\r\n\r\nWe welcome contributions to this project! Feel free to submit a pull request or\r\nopen an issue if you find a bug or have a feature request.\r\n\r\n## 📄 License\r\n\r\nThis library is licensed under the ISC License, see LICENSE for more\r\ninformation.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapeleghq%2Fts-multipart-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapeleghq%2Fts-multipart-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapeleghq%2Fts-multipart-parser/lists"}