dcmjs-org / dcmjs

Javascript implementation of DICOM manipulation
https://dcmjs.netlify.com/
MIT License
291 stars 110 forks source link

Trouble doing basic loading #311

Closed vjau closed 1 year ago

vjau commented 1 year ago

Hi, i'm trying this library for the first time and have trouble with basic operations, trying to run this in node.

With this code and provided test dicom

const dcmjs = require("dcmjs");
const fs = require('fs');
fs.readFile('IM-0001-0001.dcm', (err, data)=>{
  let dicomData = dcmjs.data.DicomMessage.readFile(data);
});

I get following error

this.view = new DataView(this.buffer);
                        ^

TypeError: First argument to DataView constructor must be an ArrayBuffer

I am not an expert in node binary handling, but i suppose a node Buffer should be accepted as an ArrayBuffer.

Or is this project only for the browser ?

Thank you.

pieper commented 1 year ago

The code should work fine in node or browser. Try with one of the test datasets and if you still have issues post the full stack trace.

vjau commented 1 year ago

The dicom file used is the one provided in your examples/data folder.

Stacktrace is here

/home/vincent/dev/temp/dcmjs-try/node_modules/dcmjs/build/dcmjs.js:829
            this.view = new DataView(this.buffer);
                        ^

TypeError: First argument to DataView constructor must be an ArrayBuffer
    at new DataView (<anonymous>)
    at new BufferStream (/home/vincent/dev/temp/dcmjs-try/node_modules/dcmjs/build/dcmjs.js:829:18)
    at ReadBufferStream._createSuperInternal (/home/vincent/dev/temp/dcmjs-try/node_modules/dcmjs/build/dcmjs.js:632:25)
    at new ReadBufferStream (/home/vincent/dev/temp/dcmjs-try/node_modules/dcmjs/build/dcmjs.js:1183:21)
    at Function.readFile (/home/vincent/dev/temp/dcmjs-try/node_modules/dcmjs/build/dcmjs.js:3579:21)
    at /home/vincent/dev/temp/dcmjs-try/main.js:4:43
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:71:3)

I have made a repro here : https://github.com/vjau/dcmjs-try

Node v14.20.0 Ubuntu 20.04

pieper commented 1 year ago

Thanks for making the sample. Did you try changing this line to data.buffer?

https://github.com/vjau/dcmjs-try/blob/1283caae8a16a37bfe5a4cc513297eaa0c3f7e33/main.js#L4

pieper commented 1 year ago

I tested with data.buffer and it appears to work. Can you confirm. I did run into [this issue](https://github.com/dcmjs-org/dcmjs/issues/319}. If you are working on nodejs could you provide a PR to fix that?

vjau commented 1 year ago

It's indeed working replacing data with data.buffer I will look into your issue.