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

Trouble doing basic loading #311

Closed
vjau opened this issue Sep 17, 2022 · 5 comments
Closed

Trouble doing basic loading #311

vjau opened this issue Sep 17, 2022 · 5 comments

Comments

@vjau
Copy link

vjau commented Sep 17, 2022

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
Copy link
Collaborator

pieper commented Sep 17, 2022

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
Copy link
Author

vjau commented Sep 17, 2022

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
Copy link
Collaborator

pieper commented Oct 4, 2022

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
Copy link
Collaborator

pieper commented Oct 5, 2022

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
Copy link
Author

vjau commented Oct 6, 2022

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

@pieper pieper closed this as completed Oct 6, 2022
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