Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
The dicer npm package is a very fast streaming multipart parser that can be used to parse multipart/form-data input. It is particularly useful for handling file uploads and multipart HTTP requests in Node.js applications.
Multipart Parsing
This code sets up a new Dicer instance with a specified boundary and listens for 'part' events to process each part of the multipart data. It also listens for the 'finish' event to know when all parts have been processed.
const Dicer = require('dicer');
const d = new Dicer({ boundary: '---------------------------168072824752491622650073' });
d.on('part', function(p) {
console.log('New part!');
p.on('data', function(data) {
console.log('Part data: ' + data.toString());
});
p.on('end', function() {
console.log('End of part');
});
});
d.on('finish', function() {
console.log('End of parts');
});
d.write('some multipart data buffer');
Busboy is a Node.js module for parsing incoming HTML form data. It is similar to dicer in that it can handle multipart/form-data, but it also supports other form data types and is often used for handling file uploads in web applications.
Multiparty is another multipart/form-data parser for Node.js. It is used for parsing form uploads and is similar to dicer. However, multiparty provides a higher-level API and can be easier to use for some developers compared to the lower-level stream handling required by dicer.
Formidable is a Node.js module for parsing form data, especially file uploads. It compares to dicer in its ability to handle multipart/form-data but also offers additional features such as file upload progress events and support for multiple file uploads.
A very fast streaming multipart parser for node.js.
Benchmarks can be found here.
npm install dicer
var inspect = require('util').inspect,
http = require('http');
var Dicer = require('dicer');
// quick and dirty way to parse multipart boundary
var RE_BOUNDARY = /^multipart\/.+?(?:; boundary=(?:(?:"(.+)")|(?:([^\s]+))))$/i,
HTML = new Buffer('<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>'),
PORT = 8080;
http.createServer(function(req, res) {
var m;
if (req.method === 'POST'
&& req.headers['content-type']
&& (m = RE_BOUNDARY.exec(req.headers['content-type']))) {
var d = new Dicer({ boundary: m[1] || m[2] });
d.on('part', function(p) {
console.log('New part!');
p.on('header', function(header) {
for (var h in header) {
console.log('Part header: k: ' + inspect(h)
+ ', v: ' + inspect(header[h]));
}
});
p.on('data', function(data) {
console.log('Part data: ' + inspect(data.toString()));
});
p.on('end', function() {
console.log('End of part\n');
});
});
d.on('finish', function() {
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, function() {
console.log('Listening for requests on port ' + PORT);
});
Dicer is a WritableStream
finish() - Emitted when all parts have been parsed and the Dicer instance has been ended.
part(< PartStream >stream) - Emitted when a new part has been found.
preamble(< PartStream >stream) - Emitted for preamble if you should happen to need it (can usually be ignored).
trailer(< Buffer >data) - Emitted when trailing data was found after the terminating boundary (as with the preamble, this can usually be ignored too).
(constructor)(< object >config) - Creates and returns a new Dicer instance with the following valid config
settings:
boundary - string - This is the boundary used to detect the beginning of a new part.
headerFirst - boolean - If true, preamble header parsing will be performed first.
maxHeaderPairs - integer - The maximum number of header key=>value pairs to parse Default: 2000 (same as node's http).
setBoundary(< string >boundary) - (void) - Sets the boundary to use for parsing and performs some initialization needed for parsing. You should only need to use this if you set headerFirst
to true in the constructor and are parsing the boundary from the preamble header.
PartStream is a ReadableStream
FAQs
A very fast streaming multipart parser for node.js
The npm package dicer receives a total of 1,504,965 weekly downloads. As such, dicer popularity was classified as popular.
We found that dicer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.