Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

multi-part-stream-parser

perry-mitchell1.1kMIT0.3.1TypeScript support: included

Multi-part form data stream parser

multipart, multi-part, form, formdata, parse, stream

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:

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();

changelog

Multi-Part-Stream-Parser Changelog

v0.3.1

2024-04-05

  • Bugfix:
    • Not all errors handled during upstream exceptions

v0.3.0

2024-04-05

  • Error event for parser emitter
  • Bugfix:
    • Stream close error unhandled

v0.2.3

2024-03-07

  • Bugfix:
    • Multiple new-line types not handled during parsing

v0.2.2

2024-03-06

  • Bugfix:
    • Stream errors not propagated

v0.2.1

2024-03-05

  • Bugfix:
    • Types not exported

v0.2.0

2024-03-05

  • New parsing logic to improve buffering

v0.1.0

2024-02-15

  • Initial release