To parse a DICOM P10 or raw byte stream, use dicomParser.parseDicom(). It accepts a Uint8Array or a Node.js Buffer as the first argument and an optional options object as the second.
Once parsed, you receive a dataSet object. You can access elements using their tag (e.g., as a string like 'x0020000d') and use helper methods like .string() to convert values to native JavaScript types. For pixel data, you can access the element to get the dataOffset and length, then create a typed array (like Uint16Array) directly from the underlying buffer.
// create a Uint8Array or node.js Buffer with the contents of the DICOM P10 byte stream
var arrayBuffer = new ArrayBuffer(bufferSize);
var byteArray = new Uint8Array(arrayBuffer);
try
{
// Allow raw files
const options = { TransferSyntaxUID: '1.2.840.10008.1.2' };
// Parse the byte array to get a DataSet object that has the parsed contents
var dataSet = dicomParser.parseDicom(byteArray, options);
// access a string element
var studyInstanceUid = dataSet.string('x0020000d');
// get the pixel data element (contains the offset and length of the data)
var pixelDataElement = dataSet.elements.x7fe00010;
// create a typed array on the pixel data (this example assumes 16 bit unsigned data)
var pixelData = new Uint16Array(dataSet.byteArray.buffer, pixelDataElement.dataOffset, pixelDataElement.length / 2);
}
catch(ex)
{
console.log('Error parsing byte stream', ex);
}