dcmjs 0.43.1 → 0.44.0

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.
package/build/dcmjs.es.js CHANGED
@@ -10888,15 +10888,23 @@ var DicomMessage = /*#__PURE__*/function () {
10888
10888
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
10889
10889
  ignoreErrors: false,
10890
10890
  untilTag: null,
10891
- includeUntilTagValue: false
10891
+ includeUntilTagValue: false,
10892
+ stopOnGreaterTag: false
10892
10893
  };
10893
10894
  var ignoreErrors = options.ignoreErrors,
10894
- untilTag = options.untilTag;
10895
+ untilTag = options.untilTag,
10896
+ stopOnGreaterTag = options.stopOnGreaterTag;
10895
10897
  var dict = {};
10896
10898
  try {
10899
+ var previousTagOffset;
10897
10900
  while (!bufferStream.end()) {
10901
+ previousTagOffset = bufferStream.offset;
10898
10902
  var readInfo = DicomMessage._readTag(bufferStream, syntax, options);
10899
10903
  var cleanTagString = readInfo.tag.toCleanString();
10904
+ if (untilTag && stopOnGreaterTag && cleanTagString > untilTag) {
10905
+ bufferStream.offset = previousTagOffset;
10906
+ break;
10907
+ }
10900
10908
  if (cleanTagString === "00080005") {
10901
10909
  if (readInfo.values.length > 0) {
10902
10910
  var coding = readInfo.values[0];
@@ -10970,15 +10978,36 @@ var DicomMessage = /*#__PURE__*/function () {
10970
10978
  if (stream.readAsciiString(4) !== "DICM") {
10971
10979
  throw new Error("Invalid DICOM file, expected header is missing");
10972
10980
  }
10981
+
10982
+ // save position before reading first tag
10983
+ var metaStartPos = stream.offset;
10984
+
10985
+ // read the first tag to check if it's the meta length tag
10973
10986
  var el = DicomMessage._readTag(stream, useSyntax);
10987
+ var metaHeader = {};
10974
10988
  if (el.tag.toCleanString() !== "00020000") {
10975
- throw new Error("Invalid DICOM file, meta length tag is malformed or not present.");
10976
- }
10977
- var metaLength = el.values[0];
10989
+ // meta length tag is missing
10990
+ if (!options.ignoreErrors) {
10991
+ throw new Error("Invalid DICOM file, meta length tag is malformed or not present.");
10992
+ }
10993
+
10994
+ // reset stream to the position where we started reading tags
10995
+ stream.offset = metaStartPos;
10996
+
10997
+ // read meta header elements sequentially
10998
+ metaHeader = DicomMessage._read(stream, useSyntax, {
10999
+ untilTag: "00030000",
11000
+ stopOnGreaterTag: true,
11001
+ ignoreErrors: true
11002
+ });
11003
+ } else {
11004
+ // meta length tag is present
11005
+ var metaLength = el.values[0];
10978
11006
 
10979
- //read header buffer
10980
- var metaStream = stream.more(metaLength);
10981
- var metaHeader = DicomMessage._read(metaStream, useSyntax, options);
11007
+ // read header buffer using the specified meta length
11008
+ var metaStream = stream.more(metaLength);
11009
+ metaHeader = DicomMessage._read(metaStream, useSyntax, options);
11010
+ }
10982
11011
 
10983
11012
  //get the syntax
10984
11013
  var mainSyntax = metaHeader["00020010"].Value[0];