@ssttevee/multipart-parser
TypeScript icon, indicating that this package has built-in type declarations

0.1.9 • Public • Published

Description

A simple multipart/form-data parser for use with ReadableStreams.

Installation

npm install @ssttevee/multipart-parser

Example

import { parseMultipart } from '@ssttevee/multipart-parser';

...

async function requestHandler(req) {
    const boundary = '----whatever';
    const parts = await parseMultipart(req.body, boundary);
    const fd = new FormData();
    for (const { name, data, filename, contentType } of parts) {
        if (filename) {
            fd.append(name, new Blob([data], { type: contentType }), filename);
        } else {
            fd.append(name, new TextDecoder().decode(data), filename);
        }
    }
}

Package Sidebar

Install

npm i @ssttevee/multipart-parser

Weekly Downloads

29

Version

0.1.9

License

MIT

Unpacked Size

20.2 kB

Total Files

6

Last publish

Collaborators

  • ssttevee