@exini/dicom-streams-js 3.0.5 → 3.0.8

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/node/index.js CHANGED
@@ -518,9 +518,7 @@ class ByteParser {
518
518
  }
519
519
  doParse(remainingRecursions) {
520
520
  if (remainingRecursions === 0) {
521
- this.fail(new Error("Parsing logic didn't produce result. Aborting processing to avoid infinite cycles. " +
522
- 'In the unlikely case that the parsing logic needs more recursion, override ' +
523
- 'ParsingLogic.recursionLimit.'));
521
+ this.fail(new Error("Parsing logic didn't produce result. Aborting processing to avoid infinite cycles."));
524
522
  }
525
523
  else {
526
524
  const doRecurse = this.doParseInner();
@@ -547,9 +545,6 @@ exports.defaultCharacterSet = exports.CharacterSets = void 0;
547
545
  const dicom_character_set_1 = __webpack_require__(/*! dicom-character-set */ "dicom-character-set");
548
546
  const vr_1 = __webpack_require__(/*! ./vr */ "./src/vr.ts");
549
547
  class CharacterSets {
550
- constructor(charsets) {
551
- this.charsets = charsets;
552
- }
553
548
  static isVrAffectedBySpecificCharacterSet(vr) {
554
549
  return vr === vr_1.VR.LO || vr === vr_1.VR.LT || vr === vr_1.VR.PN || vr === vr_1.VR.SH || vr === vr_1.VR.ST || vr === vr_1.VR.UT;
555
550
  }
@@ -559,7 +554,7 @@ class CharacterSets {
559
554
  static fromBytes(specificCharacterSetBytes) {
560
555
  return !specificCharacterSetBytes || specificCharacterSetBytes.length === 0
561
556
  ? exports.defaultCharacterSet
562
- : new CharacterSets(specificCharacterSetBytes.toString());
557
+ : new CharacterSets(specificCharacterSetBytes.toString().trim());
563
558
  }
564
559
  static encode(s) {
565
560
  return Buffer.from(s, 'utf8');
@@ -567,6 +562,9 @@ class CharacterSets {
567
562
  static defaultOnly() {
568
563
  return new CharacterSets('');
569
564
  }
565
+ constructor(charsets) {
566
+ this.charsets = charsets;
567
+ }
570
568
  decode(bytes, vr) {
571
569
  try {
572
570
  return (0, dicom_character_set_1.convertBytes)(this.charsets, bytes, { vr: vr.name });
@@ -1954,6 +1952,19 @@ class PreamblePart extends DicomPart {
1954
1952
  }
1955
1953
  exports.PreamblePart = PreamblePart;
1956
1954
  class HeaderPart extends DicomPart {
1955
+ static create(tag, vr, length, bigEndian = false, explicitVR = true) {
1956
+ const bytes = explicitVR
1957
+ ? vr.headerLength === 8
1958
+ ? Buffer.concat([(0, base_1.tagToBytes)(tag, bigEndian), Buffer.from(vr.name), (0, base_1.shortToBytes)(length, bigEndian)], 8)
1959
+ : Buffer.concat([
1960
+ (0, base_1.tagToBytes)(tag, bigEndian),
1961
+ Buffer.from(vr.name),
1962
+ Buffer.from([0, 0]),
1963
+ (0, base_1.intToBytes)(length, bigEndian),
1964
+ ], 12)
1965
+ : Buffer.concat([(0, base_1.tagToBytes)(tag, bigEndian), (0, base_1.intToBytes)(length, bigEndian)], 8);
1966
+ return new HeaderPart(tag, vr, length, (0, base_1.isFileMetaInformation)(tag), bigEndian, explicitVR, bytes);
1967
+ }
1957
1968
  constructor(tag, vr, length, isFmi, bigEndian, explicitVR, bytes) {
1958
1969
  super(bigEndian, bytes);
1959
1970
  this.tag = tag;
@@ -1976,19 +1987,6 @@ class HeaderPart extends DicomPart {
1976
1987
  : Buffer.concat([(0, base_1.tagToBytes)(tag, bigEndian), (0, base_1.intToBytes)(length, bigEndian)], 8);
1977
1988
  }
1978
1989
  }
1979
- static create(tag, vr, length, bigEndian = false, explicitVR = true) {
1980
- const bytes = explicitVR
1981
- ? vr.headerLength === 8
1982
- ? Buffer.concat([(0, base_1.tagToBytes)(tag, bigEndian), Buffer.from(vr.name), (0, base_1.shortToBytes)(length, bigEndian)], 8)
1983
- : Buffer.concat([
1984
- (0, base_1.tagToBytes)(tag, bigEndian),
1985
- Buffer.from(vr.name),
1986
- Buffer.from([0, 0]),
1987
- (0, base_1.intToBytes)(length, bigEndian),
1988
- ], 12)
1989
- : Buffer.concat([(0, base_1.tagToBytes)(tag, bigEndian), (0, base_1.intToBytes)(length, bigEndian)], 8);
1990
- return new HeaderPart(tag, vr, length, (0, base_1.isFileMetaInformation)(tag), bigEndian, explicitVR, bytes);
1991
- }
1992
1990
  withUpdatedLength(newLength) {
1993
1991
  if (newLength === this.length) {
1994
1992
  return this;
@@ -2490,15 +2488,15 @@ function parseZoneOffset(s) {
2490
2488
  }
2491
2489
  exports.parseZoneOffset = parseZoneOffset;
2492
2490
  class Elements {
2491
+ static empty(characterSets = base_1.defaultCharacterSet, zoneOffset = base_1.systemZone) {
2492
+ return new Elements(characterSets, zoneOffset, []);
2493
+ }
2493
2494
  constructor(characterSets = base_1.defaultCharacterSet, zoneOffset = base_1.systemZone, data = []) {
2494
2495
  this.characterSets = characterSets;
2495
2496
  this.zoneOffset = zoneOffset;
2496
2497
  this.data = data;
2497
2498
  this.size = data.length;
2498
2499
  }
2499
- static empty(characterSets = base_1.defaultCharacterSet, zoneOffset = base_1.systemZone) {
2500
- return new Elements(characterSets, zoneOffset, []);
2501
- }
2502
2500
  elementByTag(tag) {
2503
2501
  return this.data.find((e) => e.tag === tag);
2504
2502
  }
@@ -3313,8 +3311,8 @@ class Lookup {
3313
3311
  return uid_to_name_1.UIDToName.nameOf(uid);
3314
3312
  }
3315
3313
  }
3316
- exports.Lookup = Lookup;
3317
3314
  Lookup.keywords = Object.keys(tag_1.Tag);
3315
+ exports.Lookup = Lookup;
3318
3316
 
3319
3317
 
3320
3318
  /***/ }),
@@ -3335,16 +3333,16 @@ const dicom_parts_1 = __webpack_require__(/*! ./dicom-parts */ "./src/dicom-part
3335
3333
  const tag_path_1 = __webpack_require__(/*! ./tag-path */ "./src/tag-path.ts");
3336
3334
  const vr_1 = __webpack_require__(/*! ./vr */ "./src/vr.ts");
3337
3335
  class TagModification {
3338
- constructor(matches, modification) {
3339
- this.matches = matches;
3340
- this.modification = modification;
3341
- }
3342
3336
  static equals(tagPath, modification) {
3343
3337
  return new TagModification(tagPath.isEqualTo.bind(tagPath), modification);
3344
3338
  }
3345
3339
  static endsWith(tagPath, modification) {
3346
3340
  return new TagModification((tp) => tp.endsWith(tagPath), modification);
3347
3341
  }
3342
+ constructor(matches, modification) {
3343
+ this.matches = matches;
3344
+ this.modification = modification;
3345
+ }
3348
3346
  }
3349
3347
  exports.TagModification = TagModification;
3350
3348
  class TagInsertion {
@@ -4475,11 +4473,6 @@ const base_1 = __webpack_require__(/*! ./base */ "./src/base.ts");
4475
4473
  const lookup_1 = __webpack_require__(/*! ./lookup */ "./src/lookup.ts");
4476
4474
  const tag_path_like_1 = __webpack_require__(/*! ./tag-path-like */ "./src/tag-path-like.ts");
4477
4475
  class TagPath extends tag_path_like_1.TagPathLike {
4478
- constructor(tag, previous) {
4479
- super();
4480
- this.tagVal = tag;
4481
- this.previousVal = previous;
4482
- }
4483
4476
  static fromTag(tag) {
4484
4477
  return exports.emptyTagPath.thenTag(tag);
4485
4478
  }
@@ -4537,6 +4530,11 @@ class TagPath extends tag_path_like_1.TagPathLike {
4537
4530
  throw Error('Tag path could not be parsed: ' + error.message);
4538
4531
  }
4539
4532
  }
4533
+ constructor(tag, previous) {
4534
+ super();
4535
+ this.tagVal = tag;
4536
+ this.previousVal = previous;
4537
+ }
4540
4538
  tag() {
4541
4539
  return this.tagVal;
4542
4540
  }
@@ -4791,7 +4789,6 @@ class TagToVR {
4791
4789
  return key in TagToVR.dict ? TagToVR.dict[key] : vr_1.VR.UN;
4792
4790
  }
4793
4791
  }
4794
- exports.TagToVR = TagToVR;
4795
4792
  TagToVR.dict = {
4796
4793
  '0': vr_1.VR.UL,
4797
4794
  '2': vr_1.VR.UI,
@@ -9093,6 +9090,7 @@ TagToVR.dict = {
9093
9090
  fffafffa: vr_1.VR.SQ,
9094
9091
  fffcfffc: vr_1.VR.OB,
9095
9092
  };
9093
+ exports.TagToVR = TagToVR;
9096
9094
 
9097
9095
 
9098
9096
  /***/ }),
@@ -9111,11 +9109,6 @@ const lookup_1 = __webpack_require__(/*! ./lookup */ "./src/lookup.ts");
9111
9109
  const tag_path_1 = __webpack_require__(/*! ./tag-path */ "./src/tag-path.ts");
9112
9110
  const tag_path_like_1 = __webpack_require__(/*! ./tag-path-like */ "./src/tag-path-like.ts");
9113
9111
  class TagTree extends tag_path_like_1.TagPathLike {
9114
- constructor(tag, previous) {
9115
- super();
9116
- this.tagVal = tag;
9117
- this.previousVal = previous;
9118
- }
9119
9112
  static fromTag(tag) {
9120
9113
  return exports.emptyTagTree.thenTag(tag);
9121
9114
  }
@@ -9227,6 +9220,11 @@ class TagTree extends tag_path_like_1.TagPathLike {
9227
9220
  throw Error('Tag tree could not be parsed: ' + error.message);
9228
9221
  }
9229
9222
  }
9223
+ constructor(tag, previous) {
9224
+ super();
9225
+ this.tagVal = tag;
9226
+ this.previousVal = previous;
9227
+ }
9230
9228
  tag() {
9231
9229
  return this.tagVal;
9232
9230
  }
@@ -13827,7 +13825,6 @@ class UIDToName {
13827
13825
  return UIDToName.dict[uid];
13828
13826
  }
13829
13827
  }
13830
- exports.UIDToName = UIDToName;
13831
13828
  UIDToName.dict = {
13832
13829
  '1.2.840.10008.1.1': 'Verification SOP Class',
13833
13830
  '1.2.840.10008.1.2': 'Implicit VR Little Endian',
@@ -14239,6 +14236,7 @@ UIDToName.dict = {
14239
14236
  '1.2.840.10008.15.0.4.8': 'dicom​Transfer​Capability',
14240
14237
  '1.2.840.10008.15.1.1': 'Universal Coordinated Time',
14241
14238
  };
14239
+ exports.UIDToName = UIDToName;
14242
14240
 
14243
14241
 
14244
14242
  /***/ }),
@@ -14670,10 +14668,6 @@ const character_sets_1 = __webpack_require__(/*! ./character-sets */ "./src/char
14670
14668
  const vr_1 = __webpack_require__(/*! ./vr */ "./src/vr.ts");
14671
14669
  const person_name_1 = __webpack_require__(/*! ./person-name */ "./src/person-name.ts");
14672
14670
  class Value {
14673
- constructor(bytes) {
14674
- this.bytes = bytes;
14675
- this.length = bytes.length;
14676
- }
14677
14671
  static fromString(vr, value, bigEndian = false) {
14678
14672
  return create(stringBytes(vr, value, bigEndian), vr);
14679
14673
  }
@@ -14725,6 +14719,10 @@ class Value {
14725
14719
  static headOption(array) {
14726
14720
  return array.length > 0 ? array[0] : undefined;
14727
14721
  }
14722
+ constructor(bytes) {
14723
+ this.bytes = bytes;
14724
+ this.length = bytes.length;
14725
+ }
14728
14726
  toStrings(vr, bigEndian = false, characterSets = character_sets_1.defaultCharacterSet) {
14729
14727
  if (this.length === 0) {
14730
14728
  return [];
@@ -14738,17 +14736,23 @@ class Value {
14738
14736
  if (vr === vr_1.VR.FD) {
14739
14737
  return parseFD(this.bytes, bigEndian).map((v) => v.toString());
14740
14738
  }
14739
+ if (vr === vr_1.VR.SS) {
14740
+ return parseSS(this.bytes, bigEndian).map((v) => v.toString());
14741
+ }
14741
14742
  if (vr === vr_1.VR.SL) {
14742
14743
  return parseSL(this.bytes, bigEndian).map((v) => v.toString());
14743
14744
  }
14744
- if (vr === vr_1.VR.SS) {
14745
- return parseSS(this.bytes, bigEndian).map((v) => v.toString());
14745
+ if (vr === vr_1.VR.SV) {
14746
+ return parseSV(this.bytes, bigEndian).map((v) => v.toString());
14747
+ }
14748
+ if (vr === vr_1.VR.US) {
14749
+ return parseUS(this.bytes, bigEndian).map((v) => v.toString());
14746
14750
  }
14747
14751
  if (vr === vr_1.VR.UL) {
14748
14752
  return parseUL(this.bytes, bigEndian).map((v) => v.toString());
14749
14753
  }
14750
- if (vr === vr_1.VR.US) {
14751
- return parseUS(this.bytes, bigEndian).map((v) => v.toString());
14754
+ if (vr === vr_1.VR.UV) {
14755
+ return parseSV(this.bytes, bigEndian).map((v) => v.toString());
14752
14756
  }
14753
14757
  if (vr === vr_1.VR.OB) {
14754
14758
  return [this.bytes.length + ' bytes'];
@@ -14756,48 +14760,32 @@ class Value {
14756
14760
  if (vr === vr_1.VR.OW) {
14757
14761
  return [this.bytes.length / 2 + ' words'];
14758
14762
  }
14763
+ if (vr === vr_1.VR.OL) {
14764
+ return [this.bytes.length / 4 + ' longs'];
14765
+ }
14766
+ if (vr === vr_1.VR.OV) {
14767
+ return [this.bytes.length / 8 + ' very longs'];
14768
+ }
14759
14769
  if (vr === vr_1.VR.OF) {
14760
- return [parseFL(this.bytes, bigEndian).join(' ')];
14770
+ return [this.bytes.length / 4 + ' floats'];
14761
14771
  }
14762
14772
  if (vr === vr_1.VR.OD) {
14763
- return [parseFD(this.bytes, bigEndian).join(' ')];
14773
+ return [this.bytes.length / 8 + ' doubles'];
14764
14774
  }
14765
- if (vr === vr_1.VR.ST || vr === vr_1.VR.LT || vr === vr_1.VR.UT || vr === vr_1.VR.UR) {
14766
- return [trimPadding(characterSets.decode(this.bytes, vr), vr.paddingByte)];
14775
+ if (vr === vr_1.VR.ST || vr === vr_1.VR.LT || vr === vr_1.VR.UT) {
14776
+ return [trimTrailing(characterSets.decode(this.bytes, vr), vr.paddingByte)];
14767
14777
  }
14768
- if (vr === vr_1.VR.DA || vr === vr_1.VR.TM || vr === vr_1.VR.DT) {
14769
- return splitString(this.bytes.toString()).map(base_1.trim);
14778
+ if (vr === vr_1.VR.LO || vr === vr_1.VR.SH || vr === vr_1.VR.UC) {
14779
+ return splitString(characterSets.decode(this.bytes, vr));
14770
14780
  }
14771
- if (vr === vr_1.VR.UC) {
14772
- return splitString(trimPadding(characterSets.decode(this.bytes, vr), vr.paddingByte));
14781
+ if (vr == vr_1.VR.PN) {
14782
+ return splitString(characterSets.decode(this.bytes, vr)).map(base_1.trim);
14773
14783
  }
14774
- return splitString(characterSets.decode(this.bytes, vr)).map(base_1.trim);
14784
+ return splitString(this.bytes.toString()).map(base_1.trim);
14775
14785
  }
14776
14786
  toSingleString(vr, bigEndian = false, characterSets = character_sets_1.defaultCharacterSet) {
14777
- if (vr === vr_1.VR.AT ||
14778
- vr === vr_1.VR.FL ||
14779
- vr === vr_1.VR.FD ||
14780
- vr === vr_1.VR.SL ||
14781
- vr === vr_1.VR.SS ||
14782
- vr === vr_1.VR.UL ||
14783
- vr === vr_1.VR.US ||
14784
- vr === vr_1.VR.OB ||
14785
- vr === vr_1.VR.OW ||
14786
- vr === vr_1.VR.OF ||
14787
- vr === vr_1.VR.OD) {
14788
- const strings = this.toStrings(vr, bigEndian, characterSets);
14789
- return strings.length === 0 ? '' : strings.join(base_1.multiValueDelimiter);
14790
- }
14791
- if (vr === vr_1.VR.ST || vr === vr_1.VR.LT || vr === vr_1.VR.UT || vr === vr_1.VR.UR) {
14792
- return trimPadding(characterSets.decode(this.bytes, vr), vr.paddingByte);
14793
- }
14794
- if (vr === vr_1.VR.DA || vr === vr_1.VR.TM || vr === vr_1.VR.DT) {
14795
- return (0, base_1.trim)(this.bytes.toString());
14796
- }
14797
- if (vr === vr_1.VR.UC) {
14798
- return trimPadding(characterSets.decode(this.bytes, vr), vr.paddingByte);
14799
- }
14800
- return (0, base_1.trim)(characterSets.decode(this.bytes, vr));
14787
+ const strings = this.toStrings(vr, bigEndian, characterSets);
14788
+ return strings.length === 0 ? '' : strings.join(base_1.multiValueDelimiter);
14801
14789
  }
14802
14790
  toNumbers(vr, bigEndian = false) {
14803
14791
  if (this.length === 0) {
@@ -14897,7 +14885,7 @@ class Value {
14897
14885
  }
14898
14886
  }
14899
14887
  exports.Value = Value;
14900
- function trimPadding(s, paddingByte) {
14888
+ function trimTrailing(s, paddingByte) {
14901
14889
  let index = s.length;
14902
14890
  while (index > 0 && s.charCodeAt(index - 1) <= paddingByte) {
14903
14891
  index -= 1;
@@ -15066,6 +15054,9 @@ function parseAT(value, bigEndian = false) {
15066
15054
  function parseSL(value, bigEndian = false) {
15067
15055
  return splitFixed(value, 4).map((b) => (0, base_1.bytesToInt)(b, bigEndian));
15068
15056
  }
15057
+ function parseSV(value, bigEndian = false) {
15058
+ return splitFixed(value, 8).map((b) => (0, base_1.bytesToFloat)(b, bigEndian));
15059
+ }
15069
15060
  function parseSS(value, bigEndian = false) {
15070
15061
  return splitFixed(value, 2).map((b) => (0, base_1.bytesToShort)(b, bigEndian));
15071
15062
  }
@@ -15247,17 +15238,16 @@ function parseURL(s) {
15247
15238
  Object.defineProperty(exports, "__esModule", ({ value: true }));
15248
15239
  exports.VR = void 0;
15249
15240
  class VR {
15241
+ static valueOf(code) {
15242
+ return VR.map.get(code);
15243
+ }
15250
15244
  constructor(name, code, headerLength, paddingByte) {
15251
15245
  this.name = name;
15252
15246
  this.code = code;
15253
15247
  this.headerLength = headerLength;
15254
15248
  this.paddingByte = paddingByte;
15255
15249
  }
15256
- static valueOf(code) {
15257
- return VR.map.get(code);
15258
- }
15259
15250
  }
15260
- exports.VR = VR;
15261
15251
  VR.AE = new VR('AE', 0x4145, 8, 0x20);
15262
15252
  VR.AS = new VR('AS', 0x4153, 8, 0x20);
15263
15253
  VR.AT = new VR('AT', 0x4154, 8, 0);
@@ -15332,6 +15322,7 @@ VR.map = VR.values.reduce((m, vr) => {
15332
15322
  m.set(vr.code, vr);
15333
15323
  return m;
15334
15324
  }, new Map());
15325
+ exports.VR = VR;
15335
15326
 
15336
15327
 
15337
15328
  /***/ }),
@@ -15428,7 +15419,7 @@ module.exports = require("zlib");
15428
15419
  /******/ // Load entry module and return exports
15429
15420
  /******/ // This entry module is referenced by other modules so it can't be inlined
15430
15421
  /******/ var __webpack_exports__ = __webpack_require__("./src/index.ts");
15431
- /******/ module.exports.dicomStreams = __webpack_exports__;
15422
+ /******/ module.exports = __webpack_exports__;
15432
15423
  /******/
15433
15424
  /******/ })()
15434
15425
  ;