async-multipart-parser
v0.1.1
Published
A small streaming multipart parser built on async iterators
Readme
async-multipart-parser
A zero-dependency streaming multipart parser built on async iterators.
Usage
import {parseMultipart} from 'async-multipart-parser'
for await (const part of parseMultipart(request, {
contentType: request.headers['content-type']
})) {
console.log(part.name, part.filename, part.headers)
for await (const chunk of part.body) {
// Each chunk is a Uint8Array and can be streamed directly to a file
// or object storage without buffering the complete part in memory.
}
}API
The only public API is parseMultipart(stream, config).
stream may be a Node.js Readable, a Web ReadableStream, or any
AsyncIterable. The following configuration options are supported:
boundary: the multipart boundary.contentType: used to extract the boundary whenboundaryis omitted.maxHeaderSize: maximum header size for each part; defaults to 64 KiB.maxParts: maximum number of parts; unlimited by default.
Each part contains headers, optional name and filename properties, and a
streaming body exposed as an AsyncIterable<Uint8Array>.
Consume the current part's body before advancing to the next part. If the
body is left unconsumed, the parser discards it automatically when the outer
iterator advances.
