Skip to content

Commit a8e2d33

Browse files
authored
fix: avoid reading data once untilTag is encountered (#490)
1 parent 91e4771 commit a8e2d33

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/AsyncDicomReader.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,16 @@ export class AsyncDicomReader {
267267
// current tag can be cleared.
268268
stream.consume();
269269
const tagInfo = this.readTagHeader(options);
270+
271+
// Stop when the requested tag boundary is reached. readTagHeader()
272+
// has already consumed the 4-byte tag but nothing beyond it, so
273+
// stream.offset now points at the first byte after the tag (i.e.
274+
// the VR field for explicit-LE). Callers that need the start
275+
// offset of the tag itself should subtract 4 from stream.offset.
276+
if (tagInfo.isUntilTag) {
277+
break;
278+
}
279+
270280
const { tag, tagObj, length } = tagInfo;
271281

272282
if (tag === TagHex.ItemDelimitationEnd) {
@@ -627,7 +637,7 @@ export class AsyncDicomReader {
627637

628638
if (untilTag && untilTag === tag) {
629639
if (!includeUntilTagValue) {
630-
return { tag, tagObj, vr: 0, values: 0, untilTag: true };
640+
return { tag, tagObj, vr: 0, values: 0, isUntilTag: true };
631641
}
632642
}
633643

0 commit comments

Comments
 (0)