A simple multipart/form-data parser to use with ReadableStreams
The "@web3-storage/multipart-parser" is a robust and efficient node module designed specifically for parsing multipart/form-data with ReadableStreams. This npm package stands out due to its simplicity and effectiveness, making it an essential tool for developers working with file uploads and form data in web applications. As a derivative of the well-regarded js-multipart-parser, "@web3-storage/multipart-parser" offers a proven, streamlined approach to handling multipart data, thereby enhancing the performance and reliability of web applications.
To integrate "@web3-storage/multipart-parser" into your project, simply run the command 'npm install @web3-storage/multipart-parser' in your terminal. This installation process is quick and sets up the multipart parser to be readily available for use in your Node.js applications. By implementing this package, developers can effortlessly parse multipart/form-data from ReadableStreams, which is particularly useful in scenarios where large file handling and data integrity are crucial.
The package ensures that developers have a hassle-free experience in managing multipart data, making it an invaluable resource for projects that require the efficient handling of complex forms and file uploads. With its straightforward implementation and reliable parsing capabilities, "@web3-storage/multipart-parser" significantly reduces development time and helps maintain high standards of data processing within modern web applications.
Core dependencies of this npm package and its dev dependencies.
ipjs, playwright-test, standard, tape, typescript, web-streams-polyfill
A README file for the @web3-storage/multipart-parser code repository. View Code
A simple multipart/form-data parser to use with ReadableStreams
Based on https://github.com/ssttevee/js-multipart-parser
# install it as a dependency
$ npm i @web3-storage/multipart-parser
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);
}
}
}
You can publish by either running npm publish in the dist directory or using npx ipjs publish.