npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dicomweb-multipart-parser

v0.0.2

Published

Fast streaming multipart parser for DICOMweb STOW-RS payloads in Node.js

Readme

NPM version NPM downloads build MIT License

dicomweb-multipart-parser

A fast streaming multipart parser for DICOMweb STOW-RS payloads in Node.js.

dicomweb-multipart-parser is focused on multipart/related requests where each part is expected to be a DICOM instance. It is built for stream-first processing so you can parse large uploads without buffering entire requests in memory. This library was inspired by the dicer and busboy multipart parsers.

Install

npm install dicomweb-multipart-parser

Quick Example

const http = require('http');
const DicomwebMultipartParser = require('dicomweb-multipart-parser');

http
	.createServer((req, res) => {
		if (req.method !== 'POST' || req.url !== '/studies') {
			res.writeHead(404);
			res.end();
			return;
		}

		let dicomwebMultipartParser;
		try {
			dicomwebMultipartParser = new DicomwebMultipartParser({
				headers: req.headers,
				ignorePartsWithoutDicomPreamble: false,
			});
		} catch (err) {
			res.writeHead(400);
			res.end(err.message);
			return;
		}

		dicomwebMultipartParser.on('part', (part) => {
			// new part has arrived

			part.on('header', (header) => {
				// header values are arrays
				// e.g. header['content-type'] => ['application/dicom']
			});

			part.on('data', (chunk) => {
				// stream each DICOM part chunk to storage, processing, etc.
			});

			part.on('error', (err) => {
				// invalid part headers or optional preamble validation failures
				console.error('Part error:', err.message);
			});

			part.on('end', () => {
				// part completed
			});
		});

		dicomwebMultipartParser.on('error', (err) => {
			res.writeHead(400);
			res.end(err.message);
		});

		dicomwebMultipartParser.on('finish', () => {
			res.writeHead(200);
			res.end();
		});

		req.pipe(dicomwebMultipartParser);
	})
	.listen(8080);

API

dicomweb-multipart-parser is a Writable stream.

Constructor

const dicomwebMultipartParser = new DicomwebMultipartParser(options);

Options:

  • headers (required): request headers object containing content-type
  • partHighWaterMark (optional, number): highWaterMark used when creating each part stream
  • maxHeaderPairs (optional, number): max number of header key/value pairs parsed per part (default 2000)
  • ignorePartsWithoutDicomPreamble (optional, boolean, default false):
    • when false: parts are not preamble-validated
    • when true: part body is checked for a DICOM preamble (128-byte preamble + DICM marker) and invalid parts are ignored with a part error event

Constructor validation:

  • top-level content-type must be multipart/related
  • boundary parameter must be present
  • if content-type type parameter is present, it must be application/dicom

DicomwebMultipartParser Events

  • part(stream): emitted when a new part is found
  • finish(): emitted when multipart parsing completes
  • error(err): emitted for parser-level errors

DicomwebMultipartParser Methods

  • reset(): resets parser internals so the instance can be reused

PartStream Events

Each part is a Readable stream.

  • header(headerObject): emitted once part headers are parsed
    • header keys are lowercase
    • each header value is an array of strings
  • data(chunk): emitted for body chunks
  • end(): emitted when the part is complete
  • error(err): emitted for invalid part conditions, including:
    • missing part Content-Type header
    • unexpected part Content-Type (must be application/dicom)
    • invalid DICOM preamble when ignorePartsWithoutDicomPreamble is true

License

dicomweb-multipart-parser is released under the MIT License.