https://github.com/perry-mitchell/multi-part-stream-parser
Parse multi-part streams
https://github.com/perry-mitchell/multi-part-stream-parser
Last synced: 6 months ago
JSON representation
Parse multi-part streams
- Host: GitHub
- URL: https://github.com/perry-mitchell/multi-part-stream-parser
- Owner: perry-mitchell
- License: mit
- Created: 2024-02-13T12:35:27.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-05T18:36:32.000Z (over 2 years ago)
- Last Synced: 2025-09-21T03:30:55.578Z (10 months ago)
- Language: JavaScript
- Size: 374 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Multi-Part-Stream-Parser
> Parse multi-part form data streams
## About
**Multi-Part-Stream-Parser** provides a capture mechanism for parsing multi-part encoded streams, allowing consumers to listen for each section (split by boundary) of a multi-part document.
## Installation
Simply install by running `npm install multi-part-stream-parser --save`.
Compatible with NodeJS 18 and up.
## Usage
Pass a readable stream of multi-part data to `parseMultiPartStream`:
```typescript
import { ParseEvent, parseMultiPartStream } from "multi-part-stream-parser";
// ...
const stream = getMultiPartStream(); // get a stream somehow
const emitter = parseMultiPartStream(stream);
emitter.on(ParseEvent.SectionHeaders, (sectionName, headers) => {
// sectionName is a string, or null of not specified
// headers is an object containing lower-cased headers
});
emitter.on(ParseEvent.SectionContent, (sectionName, contentBuffer) => {
// contentBuffer is a buffer that contains the full
// contents of the section
});
emitter.on(ParseEvent.SectionContentStream, (sectionName, contentStream) => {
// contentStream is a readable stream of the section
// contents
});
// ...
// Cleanup
emitter.destroy();
await emitter.whenComplete();
```