Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
/ multipart-parser Public archive

A fast, efficient parser for multipart streams in any JavaScript environment

License

Notifications You must be signed in to change notification settings

mjackson/multipart-parser

Repository files navigation

multipart-web-stream

This is a streaming multipart parser for JavaScript with no dependencies.

Usage:

import { parseMultipartFormData, MultipartParseError } from 'multipart-web-stream';

function handleMultipartRequest(request: Request): void {
	try {
		// The parser `yield`s each part as a MultipartPart as it becomes available.
		for await (let part of parseMultipartFormData(request)) {
			console.log(part.name);
			console.log(part.filename);
			console.log(part.contentType);
			console.log(new TextDecoder().decode(part.content));
		}
	} catch (error) {
		if (error instanceof MultipartParseError) {
			console.error('Failed to parse multipart/form-data:', error.message);
		} else {
			console.error('An unexpected error occurred:', error);
		}
	}
}

About

A fast, efficient parser for multipart streams in any JavaScript environment

Resources

License

Stars

Watchers

Forks

Packages

No packages published