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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
dicomParser
✓ import dicomParser from 'dicom-parser'
✗ import { parseDicom } from 'dicom-parser'
The library primarily exports a default object containing all parsing functionalities, including `parseDicom`.
dicomParser (CommonJS)
✓ const dicomParser = require('dicom-parser')
✗ const { parseDicom } = require('dicom-parser')
Standard CommonJS import for Node.js environments. The `parseDicom` function is a method of the `dicomParser` object.
DataSet (Type)
✓ import type { DataSet } from 'dicom-parser'
Used for type-checking when working with TypeScript. The `DataSet` type represents the object returned by `parseDicom`.
Demonstrates how to initialize a byte array (mocking DICOM data) and use `dicomParser.parseDicom` to extract elements like Study Instance UID and Pixel Data, including options for raw DICOM parsing.
// In a real application, `byteArray` would come from a DICOM P10 byte stream
// (e.g., XMLHttpRequest, file read, or network stream).
// This is a minimal example to demonstrate parsing structure.
const bufferSize = 256; // Dummy size for example
const arrayBuffer = new ArrayBuffer(bufferSize);
const byteArray = new Uint8Array(arrayBuffer);
// For a valid DICOM file, you'd populate byteArray with the actual data.
// For demonstration, let's pretend it has some minimal structure.
// NOTE: This dummy byteArray will likely *not* produce a valid DICOM dataset.
// It serves to show the API usage.
try {
// Allows parsing raw DICOM (not Part 10 encapsulated) by specifying TransferSyntaxUID.
// For disk files, '1.2.840.10008.1.2' (Little Endian Implicit) is a common default.
const options = { TransferSyntaxUID: '1.2.840.10008.1.2' };
// Parse the byte array to get a DataSet object containing the parsed contents.
const dataSet = dicomParser.parseDicom(byteArray, options);
// Access a string element (e.g., Study Instance UID)
// In a real DICOM, 'x0020000d' would be the tag for StudyInstanceUID.
// This will likely be undefined in our dummy example.
const studyInstanceUid = dataSet.string('x0020000d');
console.log('Study Instance UID:', studyInstanceUid);
// Get the pixel data element (contains the offset and length of the data).
// Tag 'x7fe00010' is typically for Pixel Data.
const pixelDataElement = dataSet.elements.x7fe00010;
console.log('Pixel Data Element:', pixelDataElement);
// If pixelDataElement exists and has data, create a typed array.
// This example assumes 16-bit unsigned data, but actual type varies by DICOM.
if (pixelDataElement && pixelDataElement.length > 0) {
const pixelData = new Uint16Array(
dataSet.byteArray.buffer,
pixelDataElement.dataOffset,
pixelDataElement.length / 2
);
console.log('First few pixel data values:', pixelData.slice(0, 10));
} else {
console.log('No pixel data element found or it is empty.');
}
} catch (ex) {
console.error('Error parsing byte stream:', ex.message);
}
Errors
Common errors & fixes
Error parsing byte stream: Buffer too small to parse element tag
Attempting to parse an incomplete or malformed DICOM byte stream.
fixEnsure the input `byteArray` contains a complete and valid DICOM Part 10 file or raw DICOM data. Verify the integrity of the byte stream from its source.
Cannot read properties of undefined (reading 'string')
Attempting to access a DICOM element (e.g., `dataSet.string('x0020000d')`) that does not exist or was not successfully parsed in the `DataSet` object.
fixBefore accessing, check if the DICOM tag exists in `dataSet.elements` or if `dataSet.string()` or `dataSet.uint16()` (etc.) returns a defined value. Ensure the DICOM file contains the expected element.
Audit
Dependencies
pakooptionalRequired for supporting the Deflated Explicit VR Little Endian transfer syntax for DICOM compression.