A small, dependency-light streaming multipart parser for Node.js, written in
TypeScript. It is a maintained fork of dicer
by Brian White, modernized for ESM/TypeScript and focused on the
multipart/related payloads used by DICOMweb (e.g. STOW-RS) — while
remaining a general-purpose multipart parser usable in
OHIF, dcmjs,
and any Node service.
npm install @dcmjs/dicerThe only runtime dependency is streamsearch.
Dicer is a Writable stream. Pipe a multipart body into it and listen for
part events; each part is a Readable stream that emits a header event with
the parsed headers.
import Dicer from '@dcmjs/dicer';
const dicer = new Dicer({ boundary: 'myboundary' });
dicer.on('part', (part) => {
part.on('header', (headers) => {
// headers: Record<string, string[]>, e.g. { 'content-type': ['application/dicom'] }
});
const chunks: Buffer[] = [];
part.on('data', (chunk) => chunks.push(chunk));
part.on('end', () => {
const body = Buffer.concat(chunks);
// ...handle the completed part
});
});
dicer.on('finish', () => {
// all parts parsed
});
dicer.on('error', (err) => {
// malformed multipart data, oversized headers, early termination, etc.
});
request.pipe(dicer); // e.g. an incoming HTTP request streamThe boundary passed to Dicer is the raw boundary token (without the leading
--). When parsing an HTTP request, extract it from the Content-Type header,
for example with the content-type
package.
new Dicer({
boundary, // string: the multipart boundary token (required unless headerFirst)
headerFirst, // boolean: parse a leading header block before the first boundary
partHwm, // number: highWaterMark for each part Readable
maxHeaderPairs, // number: max header pairs per part (default 2000)
// ...plus any Node WritableOptions
});Part headers are capped at 64 KB; exceeding that emits an error.
import Dicer, { Dicer as DicerNamed, HeaderParser, PartStream } from '@dcmjs/dicer';
import type { DicerConfig, HeaderParserConfig, MultipartHeaders } from '@dcmjs/dicer';pnpm install
pnpm run build # tsc → dist/ (ESM + .d.ts)
pnpm test # vitest
pnpm run lint # eslint
pnpm run typecheck # tsc --noEmitThis package is a maintained fork of the original dicer by Brian White. The core parsing logic derives from that project; this fork modernizes it for TypeScript/ESM and the DICOMweb use case. Many thanks to the upstream author and contributors.
MIT — see LICENSE. The MIT terms of the original dicer project are preserved.