A very fast streaming multipart parser for node.js
A very fast streaming multipart parser for node.js.
Benchmarks can be found here.
npm install dicer
var inspect = inspecthttp = ;var Dicer = ;// quick and dirty way to parse multipart boundaryvar RE_BOUNDARY = /^multipart\/.+?$/iHTML = '<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;
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
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