dicom-curate 0.40.3 → 0.40.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -86801,12 +86801,18 @@ async function curateOne({
86801
86801
  const reader = new async.AsyncDicomReader();
86802
86802
  const parseFeed = cancellableReadableStreamIterable(file.stream());
86803
86803
  const feedDone = reader.stream.fromAsyncStream(parseFeed.iterable);
86804
+ const feedErrorSignal = new Promise((_, reject) => {
86805
+ feedDone.catch(reject);
86806
+ });
86804
86807
  try {
86805
- await reader.readFile({
86806
- ignoreErrors: true,
86807
- noCopy: true,
86808
- untilTag: "7FE00010"
86809
- });
86808
+ await Promise.race([
86809
+ reader.readFile({
86810
+ ignoreErrors: true,
86811
+ noCopy: true,
86812
+ untilTag: "7FE00010"
86813
+ }),
86814
+ feedErrorSignal
86815
+ ]);
86810
86816
  } finally {
86811
86817
  await parseFeed.cancel();
86812
86818
  await feedDone.catch(() => {
@@ -86939,7 +86945,11 @@ async function curateOne({
86939
86945
  create: true
86940
86946
  });
86941
86947
  const writable = await fileHandle.createWritable();
86942
- await writable.write(modifiedBlob);
86948
+ for await (const chunk of readableStreamToAsyncIterable(
86949
+ modifiedBlob.stream()
86950
+ )) {
86951
+ await writable.write(chunk);
86952
+ }
86943
86953
  await writable.close();
86944
86954
  }
86945
86955
  } else if (typeof outputTarget?.directory === "string") {
@@ -80510,12 +80510,18 @@ async function curateOne({
80510
80510
  const reader = new async.AsyncDicomReader();
80511
80511
  const parseFeed = cancellableReadableStreamIterable(file.stream());
80512
80512
  const feedDone = reader.stream.fromAsyncStream(parseFeed.iterable);
80513
+ const feedErrorSignal = new Promise((_, reject) => {
80514
+ feedDone.catch(reject);
80515
+ });
80513
80516
  try {
80514
- await reader.readFile({
80515
- ignoreErrors: true,
80516
- noCopy: true,
80517
- untilTag: "7FE00010"
80518
- });
80517
+ await Promise.race([
80518
+ reader.readFile({
80519
+ ignoreErrors: true,
80520
+ noCopy: true,
80521
+ untilTag: "7FE00010"
80522
+ }),
80523
+ feedErrorSignal
80524
+ ]);
80519
80525
  } finally {
80520
80526
  await parseFeed.cancel();
80521
80527
  await feedDone.catch(() => {
@@ -80648,7 +80654,11 @@ async function curateOne({
80648
80654
  create: true
80649
80655
  });
80650
80656
  const writable = await fileHandle.createWritable();
80651
- await writable.write(modifiedBlob);
80657
+ for await (const chunk of readableStreamToAsyncIterable(
80658
+ modifiedBlob.stream()
80659
+ )) {
80660
+ await writable.write(chunk);
80661
+ }
80652
80662
  await writable.close();
80653
80663
  }
80654
80664
  } else if (typeof outputTarget?.directory === "string") {
package/dist/esm/index.js CHANGED
@@ -88404,12 +88404,18 @@ async function curateOne({
88404
88404
  const reader = new async.AsyncDicomReader();
88405
88405
  const parseFeed = cancellableReadableStreamIterable(file.stream());
88406
88406
  const feedDone = reader.stream.fromAsyncStream(parseFeed.iterable);
88407
+ const feedErrorSignal = new Promise((_, reject) => {
88408
+ feedDone.catch(reject);
88409
+ });
88407
88410
  try {
88408
- await reader.readFile({
88409
- ignoreErrors: true,
88410
- noCopy: true,
88411
- untilTag: "7FE00010"
88412
- });
88411
+ await Promise.race([
88412
+ reader.readFile({
88413
+ ignoreErrors: true,
88414
+ noCopy: true,
88415
+ untilTag: "7FE00010"
88416
+ }),
88417
+ feedErrorSignal
88418
+ ]);
88413
88419
  } finally {
88414
88420
  await parseFeed.cancel();
88415
88421
  await feedDone.catch(() => {
@@ -88542,7 +88548,11 @@ async function curateOne({
88542
88548
  create: true
88543
88549
  });
88544
88550
  const writable = await fileHandle.createWritable();
88545
- await writable.write(modifiedBlob);
88551
+ for await (const chunk of readableStreamToAsyncIterable(
88552
+ modifiedBlob.stream()
88553
+ )) {
88554
+ await writable.write(chunk);
88555
+ }
88546
88556
  await writable.close();
88547
88557
  }
88548
88558
  } else if (typeof outputTarget?.directory === "string") {
@@ -86801,12 +86801,18 @@ async function curateOne({
86801
86801
  const reader = new async.AsyncDicomReader();
86802
86802
  const parseFeed = cancellableReadableStreamIterable(file.stream());
86803
86803
  const feedDone = reader.stream.fromAsyncStream(parseFeed.iterable);
86804
+ const feedErrorSignal = new Promise((_, reject) => {
86805
+ feedDone.catch(reject);
86806
+ });
86804
86807
  try {
86805
- await reader.readFile({
86806
- ignoreErrors: true,
86807
- noCopy: true,
86808
- untilTag: "7FE00010"
86809
- });
86808
+ await Promise.race([
86809
+ reader.readFile({
86810
+ ignoreErrors: true,
86811
+ noCopy: true,
86812
+ untilTag: "7FE00010"
86813
+ }),
86814
+ feedErrorSignal
86815
+ ]);
86810
86816
  } finally {
86811
86817
  await parseFeed.cancel();
86812
86818
  await feedDone.catch(() => {
@@ -86939,7 +86945,11 @@ async function curateOne({
86939
86945
  create: true
86940
86946
  });
86941
86947
  const writable = await fileHandle.createWritable();
86942
- await writable.write(modifiedBlob);
86948
+ for await (const chunk of readableStreamToAsyncIterable(
86949
+ modifiedBlob.stream()
86950
+ )) {
86951
+ await writable.write(chunk);
86952
+ }
86943
86953
  await writable.close();
86944
86954
  }
86945
86955
  } else if (typeof outputTarget?.directory === "string") {
@@ -55110,17 +55110,40 @@
55110
55110
  const reader = new async.AsyncDicomReader();
55111
55111
  const parseFeed = cancellableReadableStreamIterable(file.stream());
55112
55112
  const feedDone = reader.stream.fromAsyncStream(parseFeed.iterable);
55113
+ // Build a "never resolves, only rejects" sentinel from feedDone so we can
55114
+ // race it against readFile() without letting a normal feedDone resolution
55115
+ // exit the race too early (fromAsyncStream resolves after setComplete() but
55116
+ // before readFile() finishes parsing the buffered data).
55117
+ //
55118
+ // Attaching .catch() here also prevents "Uncaught (in promise)" in the
55119
+ // failure case: if the underlying ReadableStream fails (e.g. a mode-0000
55120
+ // file that Chrome reads via its network service and reports as
55121
+ // "TypeError: network error"), feedDone rejects while readFile() is still
55122
+ // blocked inside ensureAvailable() — which has no timeout and can only be
55123
+ // woken by addBuffer/setComplete, calls that never come when fromAsyncStream
55124
+ // threw. Without this early .catch() the browser fires "Uncaught (in
55125
+ // promise)" before the finally block ever runs.
55126
+ const feedErrorSignal = new Promise((_, reject) => {
55127
+ feedDone.catch(reject);
55128
+ });
55113
55129
  // Stop reading at the PixelData tag. The fixed dcmjs read() loop breaks
55114
55130
  // out of the scan when readTagHeader() returns {untilTag: true}, leaving
55115
55131
  // stream.offset pointing at the byte immediately after the 4-byte tag
55116
55132
  // (i.e. the VR field for explicit-LE). Subtracting 4 gives the start of
55117
55133
  // the PixelData tag, which is exactly the offset we need for the slice.
55118
55134
  try {
55119
- await reader.readFile({
55120
- ignoreErrors: true,
55121
- noCopy: true,
55122
- untilTag: '7FE00010',
55123
- });
55135
+ // Race readFile against feedErrorSignal: on a normal run feedErrorSignal
55136
+ // stays pending forever so readFile wins; on stream failure feedErrorSignal
55137
+ // rejects immediately, breaking the deadlock where readFile() would hang
55138
+ // waiting for data that will never arrive.
55139
+ await Promise.race([
55140
+ reader.readFile({
55141
+ ignoreErrors: true,
55142
+ noCopy: true,
55143
+ untilTag: '7FE00010',
55144
+ }),
55145
+ feedErrorSignal,
55146
+ ]);
55124
55147
  }
55125
55148
  finally {
55126
55149
  // Do not await feedDone without cancelling first: dcmjs fromAsyncStream
@@ -55268,7 +55291,12 @@
55268
55291
  create: true,
55269
55292
  });
55270
55293
  const writable = await fileHandle.createWritable();
55271
- await writable.write(modifiedBlob);
55294
+ // Write via stream() rather than write(modifiedBlob): LazyCompositeBlob
55295
+ // keeps an empty native Blob body and exposes its bytes only through the
55296
+ // overridden stream(), which write(blob) bypasses (yielding 0-byte files).
55297
+ for await (const chunk of readableStreamToAsyncIterable(modifiedBlob.stream())) {
55298
+ await writable.write(chunk);
55299
+ }
55272
55300
  await writable.close();
55273
55301
  }
55274
55302
  }
@@ -126851,17 +126879,40 @@
126851
126879
  const reader = new async.AsyncDicomReader();
126852
126880
  const parseFeed = cancellableReadableStreamIterable(file.stream());
126853
126881
  const feedDone = reader.stream.fromAsyncStream(parseFeed.iterable);
126882
+ // Build a "never resolves, only rejects" sentinel from feedDone so we can
126883
+ // race it against readFile() without letting a normal feedDone resolution
126884
+ // exit the race too early (fromAsyncStream resolves after setComplete() but
126885
+ // before readFile() finishes parsing the buffered data).
126886
+ //
126887
+ // Attaching .catch() here also prevents "Uncaught (in promise)" in the
126888
+ // failure case: if the underlying ReadableStream fails (e.g. a mode-0000
126889
+ // file that Chrome reads via its network service and reports as
126890
+ // "TypeError: network error"), feedDone rejects while readFile() is still
126891
+ // blocked inside ensureAvailable() — which has no timeout and can only be
126892
+ // woken by addBuffer/setComplete, calls that never come when fromAsyncStream
126893
+ // threw. Without this early .catch() the browser fires "Uncaught (in
126894
+ // promise)" before the finally block ever runs.
126895
+ const feedErrorSignal = new Promise((_, reject) => {
126896
+ feedDone.catch(reject);
126897
+ });
126854
126898
  // Stop reading at the PixelData tag. The fixed dcmjs read() loop breaks
126855
126899
  // out of the scan when readTagHeader() returns {untilTag: true}, leaving
126856
126900
  // stream.offset pointing at the byte immediately after the 4-byte tag
126857
126901
  // (i.e. the VR field for explicit-LE). Subtracting 4 gives the start of
126858
126902
  // the PixelData tag, which is exactly the offset we need for the slice.
126859
126903
  try {
126860
- await reader.readFile({
126861
- ignoreErrors: true,
126862
- noCopy: true,
126863
- untilTag: '7FE00010',
126864
- });
126904
+ // Race readFile against feedErrorSignal: on a normal run feedErrorSignal
126905
+ // stays pending forever so readFile wins; on stream failure feedErrorSignal
126906
+ // rejects immediately, breaking the deadlock where readFile() would hang
126907
+ // waiting for data that will never arrive.
126908
+ await Promise.race([
126909
+ reader.readFile({
126910
+ ignoreErrors: true,
126911
+ noCopy: true,
126912
+ untilTag: '7FE00010',
126913
+ }),
126914
+ feedErrorSignal,
126915
+ ]);
126865
126916
  }
126866
126917
  finally {
126867
126918
  // Do not await feedDone without cancelling first: dcmjs fromAsyncStream
@@ -127009,7 +127060,12 @@
127009
127060
  create: true,
127010
127061
  });
127011
127062
  const writable = await fileHandle.createWritable();
127012
- await writable.write(modifiedBlob);
127063
+ // Write via stream() rather than write(modifiedBlob): LazyCompositeBlob
127064
+ // keeps an empty native Blob body and exposes its bytes only through the
127065
+ // overridden stream(), which write(blob) bypasses (yielding 0-byte files).
127066
+ for await (const chunk of readableStreamToAsyncIterable(modifiedBlob.stream())) {
127067
+ await writable.write(chunk);
127068
+ }
127013
127069
  await writable.close();
127014
127070
  }
127015
127071
  }