multipasta is a cross-platform parser specifically designed for `multipart/form-data` payloads, commonly used for file uploads in web applications. It provides a stream-based API for handling incoming data, making it suitable for both Node.js environments (where it leverages Node's `Buffer` capabilities efficiently) and browser-like runtimes. The current stable version is 0.2.7, with frequent patch releases addressing bug fixes and minor improvements, as seen in recent changelogs. Minor version bumps (e.g., v0.2.0) introduce new features or behavior changes. Key differentiators include its cross-platform compatibility, TypeScript type definitions, and focus on efficient, stream-based parsing of multipart bodies.
npm install multipastaVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a multipart/form-data request body from a Node.js Readable stream, extracting both text fields and file content.
Ensure robust error handling in your application logic. Any processing of emitted parts should consider that `error` events might occur after `field` or `file` events, and that subsequent parts will not be emitted.
Applications handling file uploads should attach error listeners to `file` objects (the `FileStream` instances) in addition to the main `MultipartParser` instance to catch stream-specific errors.
Review how your application expects duplicate headers to be processed. Implement explicit logic to handle arrays of header values if needed, or ensure your `Content-Type` headers are unambiguous.
Ensure the `Content-Type` header (e.g., `multipart/form-data; boundary=xxxx`) is correctly extracted and the `boundary` option for `MultipartParser` is set to the correct `Buffer` representation of the boundary string.
Verify that `parser.on('file', (file) => { /* ... */ })` and `parser.on('field', (field) => { /* ... */ })` are correctly defined before data starts flowing into the parser, and that `file` and `field` objects are accessed within their respective event handlers.No dependency data recorded yet.