Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for reading from a readable stream #378

Open
ericlin-nz opened this issue Jan 18, 2024 · 1 comment
Open

Support for reading from a readable stream #378

ericlin-nz opened this issue Jan 18, 2024 · 1 comment

Comments

@ericlin-nz
Copy link

ericlin-nz commented Jan 18, 2024

Hi dcmjs-org,

I was wondering if there were any plans to support reading from a readable stream in the future, or if it is already possible, if you could please help point me in the right direction on how to achieve this?

Currently, I'm using dcmjs.data.DicomMessage.readFile(...) to read from an array buffer of a DICOM file read into memory. Although this does work well, I would like to be able to alleviate potential out of memory issues as I could be reading a very large DICOM file into memory, but only actually need the tags before PixelData.

Ideally, I would like to be able to pass in a readable stream and have dcmjs read up until the desired tag (similar to the readFile function) and then stop reading once dcmjs has reached the desired tag.

Example usage:

import dcmjs from "dcmjs";
import { createReadStream } from "fs";

const fileName = "example.dcm";
const readStream = createReadStream(fileName);

// Similar arguments to the readFile function
const dicomDict = dcmjs.data.DicomMessage.readStream(readStream, {
  untilTag: "7FE00010", // Skip reading PixelData
  includeUntilTagValue: false,
}

Any help would be much appreciated. Thank you!

@pieper
Copy link
Collaborator

pieper commented Jan 18, 2024

That sounds very reasonable - I don't know that anyone has plans to work on that, but if you wanted to suggest a backwards compatible way to do that it seems like a reasonable functionality to have.

I haven't really looked closely, but the current BufferStream code is basically treating the array as a stream, so having a variant that accepts a generic stream seems like it might be just a small change. Perhaps the same could be done for writing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants