11import dcmjs from "../src/index.js" ;
2- import fs from "fs" ;
32import path from "path" ;
4- import { promisify } from "util" ;
53import fsPromises from "fs/promises" ;
6- import { getZippedTestDataset , getTestDataset } from "./testUtils.js" ;
4+ import {
5+ getZippedTestDataset ,
6+ getTestDataset ,
7+ readFileAsArrayBuffer
8+ } from "./testUtils.js" ;
79
810const { DicomMetaDictionary, DicomMessage } = dcmjs . data ;
911
@@ -12,20 +14,20 @@ const areEqual = (first, second) =>
1214 first . every ( ( value , index ) => value === second [ index ] ) ;
1315
1416it ( "test_untilTag" , ( ) => {
15- const buffer = fs . readFileSync ( "test/sample-dicom.dcm" ) ;
17+ const buffer = readFileAsArrayBuffer ( "test/sample-dicom.dcm" ) ;
1618 console . time ( "readFile" ) ;
17- const fullData = DicomMessage . readFile ( buffer . buffer ) ;
19+ const fullData = DicomMessage . readFile ( buffer ) ;
1820 console . timeEnd ( "readFile" ) ;
1921
2022 console . time ( "readFile without untilTag" ) ;
21- const dicomData = DicomMessage . readFile ( buffer . buffer , {
23+ const dicomData = DicomMessage . readFile ( buffer , {
2224 untilTag : "7FE00010" ,
2325 includeUntilTagValue : false
2426 } ) ;
2527 console . timeEnd ( "readFile without untilTag" ) ;
2628
2729 console . time ( "readFile with untilTag" ) ;
28- const dicomData2 = DicomMessage . readFile ( buffer . buffer , {
30+ const dicomData2 = DicomMessage . readFile ( buffer , {
2931 untilTag : "7FE00010" ,
3032 includeUntilTagValue : true
3133 } ) ;
@@ -49,13 +51,13 @@ it("noCopy multiframe DICOM which has trailing padding", async () => {
4951 "https://github.com/dcmjs-org/data/releases/download/binary-parsing-stressors/multiframe-ultrasound.dcm" ;
5052 const dcmPath = await getTestDataset ( url , "multiframe-ultrasound.dcm" ) ;
5153 const dicomDictNoCopy = DicomMessage . readFile (
52- fs . readFileSync ( dcmPath ) . buffer ,
54+ readFileAsArrayBuffer ( dcmPath ) ,
5355 {
5456 noCopy : true
5557 }
5658 ) ;
5759
58- const dicomDict = DicomMessage . readFile ( fs . readFileSync ( dcmPath ) . buffer , {
60+ const dicomDict = DicomMessage . readFile ( readFileAsArrayBuffer ( dcmPath ) , {
5961 noCopy : false
6062 } ) ;
6163
@@ -77,13 +79,13 @@ it("noCopy multiframe DICOM with large private tags before and after the image d
7779 const dcmPath = await getTestDataset ( url , "large-private-tags.dcm" ) ;
7880
7981 const dicomDictNoCopy = DicomMessage . readFile (
80- fs . readFileSync ( dcmPath ) . buffer ,
82+ readFileAsArrayBuffer ( dcmPath ) ,
8183 {
8284 noCopy : true
8385 }
8486 ) ;
8587
86- const dicomDict = DicomMessage . readFile ( fs . readFileSync ( dcmPath ) . buffer , {
88+ const dicomDict = DicomMessage . readFile ( readFileAsArrayBuffer ( dcmPath ) , {
8789 noCopy : false
8890 } ) ;
8991
@@ -103,13 +105,13 @@ it("noCopy binary data into an ArrayBuffer", async () => {
103105 const url =
104106 "https://github.com/dcmjs-org/data/releases/download/binary-tag/binary-tag.dcm" ;
105107 const dcmPath = await getTestDataset ( url , "binary-tag.dcm" ) ;
106- const fileData = await promisify ( fs . readFile ) ( dcmPath ) ;
108+ const fileData = readFileAsArrayBuffer ( dcmPath ) ;
107109
108- const dicomDictNoCopy = DicomMessage . readFile ( fileData . buffer , {
110+ const dicomDictNoCopy = DicomMessage . readFile ( fileData , {
109111 noCopy : true
110112 } ) ;
111113
112- const dicomDict = DicomMessage . readFile ( fileData . buffer , {
114+ const dicomDict = DicomMessage . readFile ( fileData , {
113115 noCopy : false
114116 } ) ;
115117
@@ -138,9 +140,9 @@ it("noCopy test_multiframe_1", async () => {
138140 const fileNames = await fsPromises . readdir ( mrHeadPath ) ;
139141
140142 fileNames . forEach ( fileName => {
141- const arrayBuffer = fs . readFileSync (
143+ const arrayBuffer = readFileAsArrayBuffer (
142144 path . join ( mrHeadPath , fileName )
143- ) . buffer ;
145+ ) ;
144146 const dicomDictNoCopy = DicomMessage . readFile ( arrayBuffer , {
145147 noCopy : true
146148 } ) ;
@@ -168,13 +170,13 @@ it("noCopy test_fragment_multiframe", async () => {
168170 url ,
169171 "encapsulation-fragment-multiframe-b.dcm"
170172 ) ;
171- const file = fs . readFileSync ( dcmPath ) ;
173+ const file = readFileAsArrayBuffer ( dcmPath ) ;
172174
173- const dicomDict = dcmjs . data . DicomMessage . readFile ( file . buffer , {
175+ const dicomDict = dcmjs . data . DicomMessage . readFile ( file , {
174176 // ignoreErrors: true,
175177 } ) ;
176178
177- const dicomDictNoCopy = DicomMessage . readFile ( file . buffer , {
179+ const dicomDictNoCopy = DicomMessage . readFile ( file , {
178180 noCopy : true
179181 } ) ;
180182
0 commit comments