HckApm/node_modules/@web3-storage/multipart-parser
minicx 99e5f883a3 second commit 2023-12-23 14:56:27 +03:00
..
cjs/src second commit 2023-12-23 14:56:27 +03:00
esm second commit 2023-12-23 14:56:27 +03:00
src second commit 2023-12-23 14:56:27 +03:00
test second commit 2023-12-23 14:56:27 +03:00
types second commit 2023-12-23 14:56:27 +03:00
README.md second commit 2023-12-23 14:56:27 +03:00
index.js second commit 2023-12-23 14:56:27 +03:00
package.json second commit 2023-12-23 14:56:27 +03:00
tsconfig.json second commit 2023-12-23 14:56:27 +03:00

README.md

multipart-parser

A simple multipart/form-data parser to use with ReadableStreams

Based on https://github.com/ssttevee/js-multipart-parser

Install

# install it as a dependency
$ npm i @web3-storage/multipart-parser

Usage

import { parseMultipart } from '@web3-storage/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);
        }
    }
}

Releasing

You can publish by either running npm publish in the dist directory or using npx ipjs publish.