Registry / http-networking / dicer
library0.3.1jsnpmunverified

Dicer is a high-performance streaming multipart parser specifically designed for Node.js environments. It excels at efficiently processing `multipart/form-data` streams, making it suitable for handling HTTP file uploads and other multipart-encoded data with a focus on speed and low memory usage. The current stable version, 0.3.1, indicates a mature but not aggressively changing codebase. While it doesn't adhere to a rapid release cadence, its stability and proven performance make it a reliable choice for its specialized task. A key differentiator is its low-level, event-driven streaming API, providing developers with fine-grained control over the parsing process and part handling, contrasting with higher-level form parsing libraries that might buffer entire data sets. This design choice contributes to its reported efficiency and minimal memory footprint, especially beneficial for high-throughput applications where large file uploads are common. Benchmarks highlight its speed against alternatives, positioning it as a performant solution in the Node.js ecosystem.

npm install dicer
INSTALL
IMPORT
SIG · DICER
D
dicer
http-networkingjavascriptv0.3.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Dicer (CommonJS constructor)
const Dicer = require('dicer');
The primary constructor for creating a Dicer instance, typically used in CommonJS environments within Node.js applications.
Dicer (ESM default import)
import Dicer from 'dicer';
const Dicer = require('dicer'); // In an ESM file
While Dicer is primarily a CommonJS module, Node.js's interoperability allows it to be imported as a default in ESM contexts. However, direct `import Dicer from 'dicer'` might require specific `type: module` configurations or a transpiler to work reliably across all Node.js versions. For maximum compatibility in ESM, consider `import Dicer_module from 'dicer'; const Dicer = Dicer_module.default || Dicer_module;`.
Dicer (ESM named import)
import { Dicer } from 'dicer';
Dicer is exported as a CommonJS module and does not provide named exports. Attempting to use a named import like `import { Dicer } from 'dicer';` will result in an error in ESM environments. Only default imports (with CJS interoperability) or `require()` are applicable.

Demonstrates how to set up an HTTP server to receive multipart/form-data POST requests, manually extract the boundary from the `Content-Type` header, and use Dicer to parse individual parts, logging their headers and data.

const { inspect } = require('util'); const http = require('http'); const Dicer = require('dicer'); // Quick and dirty way to parse multipart boundary const RE_BOUNDARY = /^multipart\/.+?(?:; boundary=(?:(?:"(.+)")|(?:([^\s]+))))$/i; const HTML = Buffer.from(` <html><head></head><body> <form method="POST" enctype="multipart/form-data"> <input type="text" name="textfield"><br /> <input type="file" name="filefield"><br /> <input type="submit"> </form> </body></html> `); const PORT = 8080; http.createServer((req, res) => { let m; if (req.method === 'POST' && req.headers['content-type'] && (m = RE_BOUNDARY.exec(req.headers['content-type']))) { const d = new Dicer({ boundary: m[1] || m[2] }); d.on('part', (p) => { console.log('New part!'); p.on('header', (header) => { for (const h in header) { console.log( `Part header: k: ${inspect(h)}, v: ${inspect(header[h])}` ); } }); p.on('data', (data) => { console.log(`Part data: ${inspect(data.toString())}`); }); p.on('end', () => { console.log('End of part\n'); }); }); d.on('finish', () => { console.log('End of parts'); res.writeHead(200); res.end('Form submission successful!'); }); req.pipe(d); } else if (req.method === 'GET' && req.url === '/') { res.writeHead(200); res.end(HTML); } else { res.writeHead(404); res.end(); } }).listen(PORT, () => { console.log(`Listening for requests on port ${PORT}`); });
Debug
Known issues
gotchaDicer requires the multipart boundary to be explicitly passed during instantiation. It does not automatically parse the `Content-Type` header. Incorrectly extracting or providing the boundary will lead to parsing errors or an inability to process the stream.
fix
Implement robust `Content-Type` header parsing (e.g., using a regex) to extract the `boundary` parameter, and pass it to the `Dicer` constructor: `new Dicer({ boundary: extractedBoundary })`.
affects: >=0.1.0
gotchaThe `maxHeaderPairs` option defaults to 2000, limiting the maximum number of header key-value pairs parsed for each part. Forms with an unusually large number of fields (e.g., many checkboxes with unique names) could exceed this limit, leading to truncated header parsing.
fix
If expecting many headers per part, explicitly set `maxHeaderPairs` to a higher value in the `Dicer` constructor: `new Dicer({ boundary: '...', maxHeaderPairs: 5000 })`.
affects: >=0.1.0
gotchaDicer is a low-level streaming parser. Neglecting to consume or properly handle backpressure on `PartStream` instances (emitted by the 'part' event) can lead to memory issues or stream blockage. Each `PartStream` is a Readable stream and must be drained.
fix
Always attach a 'data' listener or pipe `PartStream` instances to another Writable stream. If you only need headers, ensure you call `p.resume()` on the `PartStream` to discard data and prevent backpressure buildup.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Dicer is not a constructor
Attempting to instantiate `Dicer` using an incorrect `require` or `import` syntax that doesn't correctly resolve the constructor, or trying to use `Dicer` before it's been properly assigned.
fix
Ensure `Dicer` is correctly imported as a CommonJS module: `const Dicer = require('dicer');` or handled with appropriate ESM interoperability for a CJS module.
Dicer `part` or `finish` events are not firing, or parsing unexpectedly stops.
The `boundary` string provided to the `Dicer` constructor does not accurately match the boundary specified in the `Content-Type` header of the incoming multipart stream.
fix
Double-check the regex or logic used to extract the `boundary` string from the `Content-Type` HTTP header and ensure it is passed correctly to `new Dicer({ boundary: '...' })`. The boundary must be an exact match.
Upgrade
Version history
0.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
dicer — npm install dicer · libregistry