dcmjs 0.24.2 → 0.24.3

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
@@ -794,30 +794,6 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
794
794
  };
795
795
  }
796
796
 
797
- //http://jonisalonen.com/2012/from-utf-16-to-utf-8-in-javascript/
798
- function toUTF8Array(str) {
799
- var utf8 = [];
800
-
801
- for (var i = 0; i < str.length; i++) {
802
- var charcode = str.charCodeAt(i);
803
- if (charcode < 0x80) utf8.push(charcode);else if (charcode < 0x800) {
804
- utf8.push(0xc0 | charcode >> 6, 0x80 | charcode & 0x3f);
805
- } else if (charcode < 0xd800 || charcode >= 0xe000) {
806
- utf8.push(0xe0 | charcode >> 12, 0x80 | charcode >> 6 & 0x3f, 0x80 | charcode & 0x3f);
807
- } // surrogate pair
808
- else {
809
- i++; // UTF-16 encodes 0x10000-0x10FFFF by
810
- // subtracting 0x10000 and splitting the
811
- // 20 bits of 0x0-0xFFFFF into two halves
812
-
813
- charcode = 0x10000 + ((charcode & 0x3ff) << 10 | str.charCodeAt(i) & 0x3ff);
814
- utf8.push(0xf0 | charcode >> 18, 0x80 | charcode >> 12 & 0x3f, 0x80 | charcode >> 6 & 0x3f, 0x80 | charcode & 0x3f);
815
- }
816
- }
817
-
818
- return utf8;
819
- }
820
-
821
797
  function toInt(val) {
822
798
  if (isNaN(val)) {
823
799
  throw new Error("Not a number: " + val);
@@ -848,6 +824,7 @@ var BufferStream = /*#__PURE__*/function () {
848
824
  this.offset = 0;
849
825
  this.isLittleEndian = littleEndian || false;
850
826
  this.size = 0;
827
+ this.encoder = new TextEncoder("utf-8");
851
828
  }
852
829
 
853
830
  _createClass(BufferStream, [{
@@ -862,6 +839,18 @@ var BufferStream = /*#__PURE__*/function () {
862
839
  this.view.setUint8(this.offset, toInt(value));
863
840
  return this.increment(1);
864
841
  }
842
+ }, {
843
+ key: "writeUint8Repeat",
844
+ value: function writeUint8Repeat(value, count) {
845
+ var v = toInt(value);
846
+ this.checkSize(count);
847
+
848
+ for (var i = 0; i < count; i++) {
849
+ this.view.setUint8(this.offset + i, v);
850
+ }
851
+
852
+ return this.increment(count);
853
+ }
865
854
  }, {
866
855
  key: "writeInt8",
867
856
  value: function writeInt8(value) {
@@ -922,48 +911,27 @@ var BufferStream = /*#__PURE__*/function () {
922
911
  return this.increment(8);
923
912
  }
924
913
  }, {
925
- key: "writeString",
926
- value: function writeString(value) {
927
- value = value || "";
928
- var utf8 = toUTF8Array(value),
929
- bytelen = utf8.length;
930
- this.checkSize(bytelen);
931
- var startOffset = this.offset;
932
-
933
- for (var i = 0; i < bytelen; i++) {
934
- this.view.setUint8(startOffset, utf8[i]);
935
- startOffset++;
936
- }
937
-
938
- return this.increment(bytelen);
914
+ key: "writeUTF8String",
915
+ value: function writeUTF8String(value) {
916
+ var encodedString = this.encoder.encode(value);
917
+ this.checkSize(encodedString.byteLength);
918
+ new Uint8Array(this.buffer).set(encodedString, this.offset);
919
+ return this.increment(encodedString.byteLength);
939
920
  }
940
921
  }, {
941
- key: "writeHex",
942
- value: function writeHex(value) {
943
- var len = value.length,
944
- blen = len / 2,
945
- startOffset = this.offset;
946
- this.checkSize(blen);
947
-
948
- for (var i = 0; i < len; i += 2) {
949
- var code = parseInt(value[i], 16),
950
- nextCode;
951
-
952
- if (i == len - 1) {
953
- nextCode = null;
954
- } else {
955
- nextCode = parseInt(value[i + 1], 16);
956
- }
957
-
958
- if (nextCode !== null) {
959
- code = code << 4 | nextCode;
960
- }
922
+ key: "writeAsciiString",
923
+ value: function writeAsciiString(value) {
924
+ value = value || "";
925
+ var len = value.length;
926
+ this.checkSize(len);
927
+ var startOffset = this.offset;
961
928
 
962
- this.view.setUint8(startOffset, code);
963
- startOffset++;
929
+ for (var i = 0; i < len; i++) {
930
+ var charcode = value.charCodeAt(i);
931
+ this.view.setUint8(startOffset + i, charcode);
964
932
  }
965
933
 
966
- return this.increment(blen);
934
+ return this.increment(len);
967
935
  }
968
936
  }, {
969
937
  key: "readUint32",
@@ -986,6 +954,11 @@ var BufferStream = /*#__PURE__*/function () {
986
954
  this.increment(1);
987
955
  return val;
988
956
  }
957
+ }, {
958
+ key: "peekUint8",
959
+ value: function peekUint8(offset) {
960
+ return this.view.getUint8(this.offset + offset);
961
+ }
989
962
  }, {
990
963
  key: "readUint8Array",
991
964
  value: function readUint8Array(length) {
@@ -1036,9 +1009,9 @@ var BufferStream = /*#__PURE__*/function () {
1036
1009
  return val;
1037
1010
  }
1038
1011
  }, {
1039
- key: "readString",
1040
- value: function readString(length) {
1041
- var chars = [];
1012
+ key: "readAsciiString",
1013
+ value: function readAsciiString(length) {
1014
+ var result = "";
1042
1015
  var start = this.offset;
1043
1016
  var end = this.offset + length;
1044
1017
 
@@ -1047,11 +1020,30 @@ var BufferStream = /*#__PURE__*/function () {
1047
1020
  }
1048
1021
 
1049
1022
  for (var i = start; i < end; ++i) {
1050
- chars.push(String.fromCharCode(this.view.getUint8(i)));
1051
- this.increment(1);
1023
+ result += String.fromCharCode(this.view.getUint8(i));
1024
+ }
1025
+
1026
+ this.increment(end - start);
1027
+ return result;
1028
+ }
1029
+ }, {
1030
+ key: "readVR",
1031
+ value: function readVR() {
1032
+ var vr = String.fromCharCode(this.view.getUint8(this.offset)) + String.fromCharCode(this.view.getUint8(this.offset + 1));
1033
+ this.increment(2);
1034
+ return vr;
1035
+ }
1036
+ }, {
1037
+ key: "readEncodedString",
1038
+ value: function readEncodedString(length) {
1039
+ if (this.offset + length >= this.buffer.byteLength) {
1040
+ length = this.buffer.byteLength - this.offset;
1052
1041
  }
1053
1042
 
1054
- return chars.join("");
1043
+ var view = new DataView(this.buffer, this.offset, length);
1044
+ var result = this.decoder.decode(view);
1045
+ this.increment(length);
1046
+ return result;
1055
1047
  }
1056
1048
  }, {
1057
1049
  key: "readHex",
@@ -1188,10 +1180,16 @@ var ReadBufferStream = /*#__PURE__*/function (_BufferStream) {
1188
1180
  _this.noCopy = options.noCopy;
1189
1181
  _this.startOffset = _this.offset;
1190
1182
  _this.endOffset = _this.size;
1183
+ _this.decoder = new TextDecoder("latin1");
1191
1184
  return _this;
1192
1185
  }
1193
1186
 
1194
1187
  _createClass(ReadBufferStream, [{
1188
+ key: "setDecoder",
1189
+ value: function setDecoder(decoder) {
1190
+ this.decoder = decoder;
1191
+ }
1192
+ }, {
1195
1193
  key: "getBuffer",
1196
1194
  value: function getBuffer(start, end) {
1197
1195
  if (this.noCopy) {
@@ -1205,24 +1203,6 @@ var ReadBufferStream = /*#__PURE__*/function (_BufferStream) {
1205
1203
 
1206
1204
  return this.buffer.slice(start, end);
1207
1205
  }
1208
- }, {
1209
- key: "readString",
1210
- value: function readString(length) {
1211
- var chars = [];
1212
- var start = this.offset;
1213
- var end = this.offset + length;
1214
-
1215
- if (end >= this.endOffset) {
1216
- end = this.endOffset;
1217
- }
1218
-
1219
- for (var i = start; i < end; ++i) {
1220
- chars.push(String.fromCharCode(this.view.getUint8(i)));
1221
- this.increment(1);
1222
- }
1223
-
1224
- return chars.join("");
1225
- }
1226
1206
  }, {
1227
1207
  key: "reset",
1228
1208
  value: function reset() {
@@ -1244,6 +1224,11 @@ var ReadBufferStream = /*#__PURE__*/function (_BufferStream) {
1244
1224
  value: function writeUint8(value) {
1245
1225
  throw new Error(value, "writeUint8 not implemented");
1246
1226
  }
1227
+ }, {
1228
+ key: "writeUint8Repeat",
1229
+ value: function writeUint8Repeat(value, count) {
1230
+ throw new Error(value, "writeUint8Repeat not implemented");
1231
+ }
1247
1232
  }, {
1248
1233
  key: "writeInt8",
1249
1234
  value: function writeInt8(value) {
@@ -1285,14 +1270,14 @@ var ReadBufferStream = /*#__PURE__*/function (_BufferStream) {
1285
1270
  throw new Error(value, "writeDouble not implemented");
1286
1271
  }
1287
1272
  }, {
1288
- key: "writeString",
1289
- value: function writeString(value) {
1290
- throw new Error(value, "writeString not implemented");
1273
+ key: "writeAsciiString",
1274
+ value: function writeAsciiString(value) {
1275
+ throw new Error(value, "writeAsciiString not implemented");
1291
1276
  }
1292
1277
  }, {
1293
- key: "writeHex",
1294
- value: function writeHex(value) {
1295
- throw new Error(value, "writeHex not implemented");
1278
+ key: "writeUTF8String",
1279
+ value: function writeUTF8String(value) {
1280
+ throw new Error(value, "writeUTF8String not implemented");
1296
1281
  }
1297
1282
  }, {
1298
1283
  key: "checkSize",
@@ -1351,22 +1336,25 @@ var ValueRepresentation = /*#__PURE__*/function () {
1351
1336
 
1352
1337
  this.type = type;
1353
1338
  this.multi = false;
1339
+ this._isBinary = binaryVRs.indexOf(this.type) != -1;
1340
+ this._allowMultiple = !this._isBinary && singleVRs.indexOf(this.type) == -1;
1341
+ this._isExplicit = explicitVRs.indexOf(this.type) != -1;
1354
1342
  }
1355
1343
 
1356
1344
  _createClass(ValueRepresentation, [{
1357
1345
  key: "isBinary",
1358
1346
  value: function isBinary() {
1359
- return binaryVRs.indexOf(this.type) != -1;
1347
+ return this._isBinary;
1360
1348
  }
1361
1349
  }, {
1362
1350
  key: "allowMultiple",
1363
1351
  value: function allowMultiple() {
1364
- return !this.isBinary() && singleVRs.indexOf(this.type) == -1;
1352
+ return this._allowMultiple;
1365
1353
  }
1366
1354
  }, {
1367
1355
  key: "isExplicit",
1368
1356
  value: function isExplicit() {
1369
- return explicitVRs.indexOf(this.type) != -1;
1357
+ return this._isExplicit;
1370
1358
  }
1371
1359
  }, {
1372
1360
  key: "read",
@@ -1381,34 +1369,19 @@ var ValueRepresentation = /*#__PURE__*/function () {
1381
1369
  }, {
1382
1370
  key: "readBytes",
1383
1371
  value: function readBytes(stream, length) {
1384
- return stream.readString(length);
1372
+ return stream.readAsciiString(length);
1385
1373
  }
1386
1374
  }, {
1387
1375
  key: "readNullPaddedString",
1388
1376
  value: function readNullPaddedString(stream, length) {
1389
1377
  if (!length) return "";
1390
- var str = stream.readString(length - 1);
1391
1378
 
1392
- if (stream.readUint8() != 0) {
1393
- stream.increment(-1);
1394
- str += stream.readString(1);
1395
- }
1396
-
1397
- return str;
1398
- }
1399
- }, {
1400
- key: "writeFilledString",
1401
- value: function writeFilledString(stream, value, length) {
1402
- if (length < this.maxLength && length >= 0) {
1403
- var written = 0;
1404
- if (length > 0) written += stream.writeString(value);
1405
- var zeroLength = this.maxLength - length;
1406
- written += stream.writeHex(this.fillWith.repeat(zeroLength));
1407
- return written;
1408
- } else if (length == this.maxLength) {
1409
- return stream.writeString(value);
1379
+ if (stream.peekUint8(length - 1) !== 0) {
1380
+ return stream.readAsciiString(length);
1410
1381
  } else {
1411
- throw "Length mismatch";
1382
+ var val = stream.readAsciiString(length - 1);
1383
+ stream.increment(1);
1384
+ return val;
1412
1385
  }
1413
1386
  }
1414
1387
  }, {
@@ -1417,7 +1390,7 @@ var ValueRepresentation = /*#__PURE__*/function () {
1417
1390
  var args = Array.from(arguments);
1418
1391
 
1419
1392
  if (args[2] === null || args[2] === "" || args[2] === undefined) {
1420
- return [stream.writeString("")];
1393
+ return [stream.writeAsciiString("")];
1421
1394
  } else {
1422
1395
  var written = [],
1423
1396
  valueArgs = args.slice(2),
@@ -1430,7 +1403,7 @@ var ValueRepresentation = /*#__PURE__*/function () {
1430
1403
  var self = this;
1431
1404
  valueArgs[0].forEach(function (v, k) {
1432
1405
  if (self.allowMultiple() && k > 0) {
1433
- stream.writeHex("5C"); //byteCount++;
1406
+ stream.writeUint8(0x5c);
1434
1407
  }
1435
1408
 
1436
1409
  var singularArgs = [v].concat(valueArgs.slice(1));
@@ -1492,7 +1465,7 @@ var ValueRepresentation = /*#__PURE__*/function () {
1492
1465
  var written = total;
1493
1466
 
1494
1467
  if (total & 1) {
1495
- stream.writeHex(this.padByte);
1468
+ stream.writeUint8(this.padByte);
1496
1469
  written++;
1497
1470
  }
1498
1471
 
@@ -1501,19 +1474,23 @@ var ValueRepresentation = /*#__PURE__*/function () {
1501
1474
  }], [{
1502
1475
  key: "createByTypeString",
1503
1476
  value: function createByTypeString(type) {
1504
- var vr = null;
1505
- if (type == "AE") vr = new ApplicationEntity();else if (type == "AS") vr = new AgeString();else if (type == "AT") vr = new AttributeTag();else if (type == "CS") vr = new CodeString();else if (type == "DA") vr = new DateValue();else if (type == "DS") vr = new DecimalString();else if (type == "DT") vr = new DateTime();else if (type == "FL") vr = new FloatingPointSingle();else if (type == "FD") vr = new FloatingPointDouble();else if (type == "IS") vr = new IntegerString();else if (type == "LO") vr = new LongString();else if (type == "LT") vr = new LongText();else if (type == "OB") vr = new OtherByteString();else if (type == "OD") vr = new OtherDoubleString();else if (type == "OF") vr = new OtherFloatString();else if (type == "OW") vr = new OtherWordString();else if (type == "PN") vr = new PersonName();else if (type == "SH") vr = new ShortString();else if (type == "SL") vr = new SignedLong();else if (type == "SQ") vr = new SequenceOfItems();else if (type == "SS") vr = new SignedShort();else if (type == "ST") vr = new ShortText();else if (type == "TM") vr = new TimeValue();else if (type == "UC") vr = new UnlimitedCharacters();else if (type == "UI") vr = new UniqueIdentifier();else if (type == "UL") vr = new UnsignedLong();else if (type == "UN") vr = new UnknownValue();else if (type == "UR") vr = new UniversalResource();else if (type == "US") vr = new UnsignedShort();else if (type == "UT") vr = new UnlimitedText();else if (type == "ox") {
1506
- // TODO: determine VR based on context (could be 1 byte pixel data)
1507
- // https://github.com/dgobbi/vtk-dicom/issues/38
1508
- log.error("Invalid vr type " + type + " - using OW");
1509
- vr = new OtherWordString();
1510
- } else if (type == "xs") {
1511
- log.error("Invalid vr type " + type + " - using US");
1512
- vr = new UnsignedShort();
1513
- } else {
1514
- log.error("Invalid vr type " + type + " - using UN");
1515
- vr = new UnknownValue();
1477
+ var vr = VRinstances[type];
1478
+
1479
+ if (vr === undefined) {
1480
+ if (type == "ox") {
1481
+ // TODO: determine VR based on context (could be 1 byte pixel data)
1482
+ // https://github.com/dgobbi/vtk-dicom/issues/38
1483
+ log.error("Invalid vr type " + type + " - using OW");
1484
+ vr = VRinstances["OW"];
1485
+ } else if (type == "xs") {
1486
+ log.error("Invalid vr type " + type + " - using US");
1487
+ vr = VRinstances["US"];
1488
+ } else {
1489
+ log.error("Invalid vr type " + type + " - using UN");
1490
+ vr = VRinstances["UN"];
1491
+ }
1516
1492
  }
1493
+
1517
1494
  return vr;
1518
1495
  }
1519
1496
  }]);
@@ -1521,46 +1498,71 @@ var ValueRepresentation = /*#__PURE__*/function () {
1521
1498
  return ValueRepresentation;
1522
1499
  }();
1523
1500
 
1524
- var StringRepresentation = /*#__PURE__*/function (_ValueRepresentation) {
1525
- _inherits(StringRepresentation, _ValueRepresentation);
1501
+ var AsciiStringRepresentation = /*#__PURE__*/function (_ValueRepresentation) {
1502
+ _inherits(AsciiStringRepresentation, _ValueRepresentation);
1526
1503
 
1527
- var _super = _createSuper(StringRepresentation);
1504
+ var _super = _createSuper(AsciiStringRepresentation);
1528
1505
 
1529
- function StringRepresentation(type) {
1530
- _classCallCheck(this, StringRepresentation);
1506
+ function AsciiStringRepresentation(type) {
1507
+ _classCallCheck(this, AsciiStringRepresentation);
1531
1508
 
1532
1509
  return _super.call(this, type);
1533
1510
  }
1534
1511
 
1535
- _createClass(StringRepresentation, [{
1512
+ _createClass(AsciiStringRepresentation, [{
1536
1513
  key: "readBytes",
1537
1514
  value: function readBytes(stream, length) {
1538
- return stream.readString(length);
1515
+ return stream.readAsciiString(length);
1539
1516
  }
1540
1517
  }, {
1541
1518
  key: "writeBytes",
1542
1519
  value: function writeBytes(stream, value, writeOptions) {
1543
- // TODO will delete
1544
- if (!writeOptions) throw new Error("writeOptions is undefined");
1520
+ var written = _get(_getPrototypeOf(AsciiStringRepresentation.prototype), "write", this).call(this, stream, "AsciiString", value);
1521
+
1522
+ return _get(_getPrototypeOf(AsciiStringRepresentation.prototype), "writeBytes", this).call(this, stream, value, written, writeOptions);
1523
+ }
1524
+ }]);
1525
+
1526
+ return AsciiStringRepresentation;
1527
+ }(ValueRepresentation);
1545
1528
 
1546
- var written = _get(_getPrototypeOf(StringRepresentation.prototype), "write", this).call(this, stream, "String", value);
1529
+ var EncodedStringRepresentation = /*#__PURE__*/function (_ValueRepresentation2) {
1530
+ _inherits(EncodedStringRepresentation, _ValueRepresentation2);
1547
1531
 
1548
- return _get(_getPrototypeOf(StringRepresentation.prototype), "writeBytes", this).call(this, stream, value, written, writeOptions);
1532
+ var _super2 = _createSuper(EncodedStringRepresentation);
1533
+
1534
+ function EncodedStringRepresentation(type) {
1535
+ _classCallCheck(this, EncodedStringRepresentation);
1536
+
1537
+ return _super2.call(this, type);
1538
+ }
1539
+
1540
+ _createClass(EncodedStringRepresentation, [{
1541
+ key: "readBytes",
1542
+ value: function readBytes(stream, length) {
1543
+ return stream.readEncodedString(length);
1544
+ }
1545
+ }, {
1546
+ key: "writeBytes",
1547
+ value: function writeBytes(stream, value, writeOptions) {
1548
+ var written = _get(_getPrototypeOf(EncodedStringRepresentation.prototype), "write", this).call(this, stream, "UTF8String", value);
1549
+
1550
+ return _get(_getPrototypeOf(EncodedStringRepresentation.prototype), "writeBytes", this).call(this, stream, value, written, writeOptions);
1549
1551
  }
1550
1552
  }]);
1551
1553
 
1552
- return StringRepresentation;
1554
+ return EncodedStringRepresentation;
1553
1555
  }(ValueRepresentation);
1554
1556
 
1555
- var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation2) {
1556
- _inherits(BinaryRepresentation, _ValueRepresentation2);
1557
+ var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation3) {
1558
+ _inherits(BinaryRepresentation, _ValueRepresentation3);
1557
1559
 
1558
- var _super2 = _createSuper(BinaryRepresentation);
1560
+ var _super3 = _createSuper(BinaryRepresentation);
1559
1561
 
1560
1562
  function BinaryRepresentation(type) {
1561
1563
  _classCallCheck(this, BinaryRepresentation);
1562
1564
 
1563
- return _super2.call(this, type);
1565
+ return _super3.call(this, type);
1564
1566
  }
1565
1567
 
1566
1568
  _createClass(BinaryRepresentation, [{
@@ -1639,7 +1641,7 @@ var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation2) {
1639
1641
  var written = 8 + binaryStream.size + startOffset.length * 4 + 8;
1640
1642
 
1641
1643
  if (written & 1) {
1642
- stream.writeHex(this.padByte);
1644
+ stream.writeUint8(this.padByte);
1643
1645
  written++;
1644
1646
  }
1645
1647
 
@@ -1789,95 +1791,93 @@ var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation2) {
1789
1791
  return BinaryRepresentation;
1790
1792
  }(ValueRepresentation);
1791
1793
 
1792
- var ApplicationEntity = /*#__PURE__*/function (_StringRepresentation) {
1793
- _inherits(ApplicationEntity, _StringRepresentation);
1794
+ var ApplicationEntity = /*#__PURE__*/function (_AsciiStringRepresent) {
1795
+ _inherits(ApplicationEntity, _AsciiStringRepresent);
1794
1796
 
1795
- var _super3 = _createSuper(ApplicationEntity);
1797
+ var _super4 = _createSuper(ApplicationEntity);
1796
1798
 
1797
1799
  function ApplicationEntity() {
1798
1800
  var _this;
1799
1801
 
1800
1802
  _classCallCheck(this, ApplicationEntity);
1801
1803
 
1802
- _this = _super3.call(this, "AE");
1804
+ _this = _super4.call(this, "AE");
1803
1805
  _this.maxLength = 16;
1804
- _this.padByte = "20";
1805
- _this.fillWith = "20";
1806
+ _this.padByte = 0x20;
1806
1807
  return _this;
1807
1808
  }
1808
1809
 
1809
1810
  _createClass(ApplicationEntity, [{
1810
1811
  key: "readBytes",
1811
1812
  value: function readBytes(stream, length) {
1812
- return stream.readString(length).trim();
1813
+ return stream.readAsciiString(length).trim();
1813
1814
  }
1814
1815
  }]);
1815
1816
 
1816
1817
  return ApplicationEntity;
1817
- }(StringRepresentation);
1818
+ }(AsciiStringRepresentation);
1818
1819
 
1819
- var CodeString = /*#__PURE__*/function (_StringRepresentation2) {
1820
- _inherits(CodeString, _StringRepresentation2);
1820
+ var CodeString = /*#__PURE__*/function (_AsciiStringRepresent2) {
1821
+ _inherits(CodeString, _AsciiStringRepresent2);
1821
1822
 
1822
- var _super4 = _createSuper(CodeString);
1823
+ var _super5 = _createSuper(CodeString);
1823
1824
 
1824
1825
  function CodeString() {
1825
1826
  var _this2;
1826
1827
 
1827
1828
  _classCallCheck(this, CodeString);
1828
1829
 
1829
- _this2 = _super4.call(this, "CS");
1830
+ _this2 = _super5.call(this, "CS");
1830
1831
  _this2.maxLength = 16;
1831
- _this2.padByte = "20";
1832
+ _this2.padByte = 0x20;
1832
1833
  return _this2;
1833
1834
  }
1834
1835
 
1835
1836
  _createClass(CodeString, [{
1836
1837
  key: "readBytes",
1837
1838
  value: function readBytes(stream, length) {
1838
- //return this.readNullPaddedString(stream, length).trim();
1839
- return stream.readString(length).trim();
1839
+ return stream.readAsciiString(length).trim();
1840
1840
  }
1841
1841
  }]);
1842
1842
 
1843
1843
  return CodeString;
1844
- }(StringRepresentation);
1844
+ }(AsciiStringRepresentation);
1845
1845
 
1846
- var AgeString = /*#__PURE__*/function (_StringRepresentation3) {
1847
- _inherits(AgeString, _StringRepresentation3);
1846
+ var AgeString = /*#__PURE__*/function (_AsciiStringRepresent3) {
1847
+ _inherits(AgeString, _AsciiStringRepresent3);
1848
1848
 
1849
- var _super5 = _createSuper(AgeString);
1849
+ var _super6 = _createSuper(AgeString);
1850
1850
 
1851
1851
  function AgeString() {
1852
1852
  var _this3;
1853
1853
 
1854
1854
  _classCallCheck(this, AgeString);
1855
1855
 
1856
- _this3 = _super5.call(this, "AS");
1856
+ _this3 = _super6.call(this, "AS");
1857
1857
  _this3.maxLength = 4;
1858
- _this3.padByte = "20";
1858
+ _this3.padByte = 0x20;
1859
1859
  _this3.fixed = true;
1860
1860
  _this3.defaultValue = "";
1861
1861
  return _this3;
1862
1862
  }
1863
1863
 
1864
1864
  return _createClass(AgeString);
1865
- }(StringRepresentation);
1865
+ }(AsciiStringRepresentation);
1866
1866
 
1867
- var AttributeTag = /*#__PURE__*/function (_ValueRepresentation3) {
1868
- _inherits(AttributeTag, _ValueRepresentation3);
1867
+ var AttributeTag = /*#__PURE__*/function (_ValueRepresentation4) {
1868
+ _inherits(AttributeTag, _ValueRepresentation4);
1869
1869
 
1870
- var _super6 = _createSuper(AttributeTag);
1870
+ var _super7 = _createSuper(AttributeTag);
1871
1871
 
1872
1872
  function AttributeTag() {
1873
1873
  var _this4;
1874
1874
 
1875
1875
  _classCallCheck(this, AttributeTag);
1876
1876
 
1877
- _this4 = _super6.call(this, "AT");
1877
+ _this4 = _super7.call(this, "AT");
1878
1878
  _this4.maxLength = 4;
1879
1879
  _this4.valueLength = 4;
1880
- _this4.padByte = "00";
1880
+ _this4.padByte = 0;
1881
1881
  _this4.fixed = true;
1882
1882
  return _this4;
1883
1883
  }
@@ -1897,49 +1897,48 @@ var AttributeTag = /*#__PURE__*/function (_ValueRepresentation3) {
1897
1897
  return AttributeTag;
1898
1898
  }(ValueRepresentation);
1899
1899
 
1900
- var DateValue = /*#__PURE__*/function (_StringRepresentation4) {
1901
- _inherits(DateValue, _StringRepresentation4);
1900
+ var DateValue = /*#__PURE__*/function (_AsciiStringRepresent4) {
1901
+ _inherits(DateValue, _AsciiStringRepresent4);
1902
1902
 
1903
- var _super7 = _createSuper(DateValue);
1903
+ var _super8 = _createSuper(DateValue);
1904
1904
 
1905
1905
  function DateValue(value) {
1906
1906
  var _this5;
1907
1907
 
1908
1908
  _classCallCheck(this, DateValue);
1909
1909
 
1910
- _this5 = _super7.call(this, "DA", value);
1910
+ _this5 = _super8.call(this, "DA", value);
1911
1911
  _this5.maxLength = 18;
1912
- _this5.padByte = "20"; //this.fixed = true;
1912
+ _this5.padByte = 0x20; //this.fixed = true;
1913
1913
 
1914
1914
  _this5.defaultValue = "";
1915
1915
  return _this5;
1916
1916
  }
1917
1917
 
1918
1918
  return _createClass(DateValue);
1919
- }(StringRepresentation);
1919
+ }(AsciiStringRepresentation);
1920
1920
 
1921
- var DecimalString = /*#__PURE__*/function (_StringRepresentation5) {
1922
- _inherits(DecimalString, _StringRepresentation5);
1921
+ var DecimalString = /*#__PURE__*/function (_AsciiStringRepresent5) {
1922
+ _inherits(DecimalString, _AsciiStringRepresent5);
1923
1923
 
1924
- var _super8 = _createSuper(DecimalString);
1924
+ var _super9 = _createSuper(DecimalString);
1925
1925
 
1926
1926
  function DecimalString() {
1927
1927
  var _this6;
1928
1928
 
1929
1929
  _classCallCheck(this, DecimalString);
1930
1930
 
1931
- _this6 = _super8.call(this, "DS");
1931
+ _this6 = _super9.call(this, "DS");
1932
1932
  _this6.maxLength = 16;
1933
- _this6.padByte = "20";
1933
+ _this6.padByte = 0x20;
1934
1934
  return _this6;
1935
1935
  }
1936
1936
 
1937
1937
  _createClass(DecimalString, [{
1938
1938
  key: "readBytes",
1939
1939
  value: function readBytes(stream, length) {
1940
- var BACKSLASH = String.fromCharCode(0x5c); //return this.readNullPaddedString(stream, length).trim();
1941
-
1942
- var ds = stream.readString(length);
1940
+ var BACKSLASH = String.fromCharCode(0x5c);
1941
+ var ds = stream.readAsciiString(length);
1943
1942
  ds = ds.replace(/[^0-9.\\\-+e]/gi, "");
1944
1943
 
1945
1944
  if (ds.indexOf(BACKSLASH) !== -1) {
@@ -1982,40 +1981,40 @@ var DecimalString = /*#__PURE__*/function (_StringRepresentation5) {
1982
1981
  }]);
1983
1982
 
1984
1983
  return DecimalString;
1985
- }(StringRepresentation);
1984
+ }(AsciiStringRepresentation);
1986
1985
 
1987
- var DateTime = /*#__PURE__*/function (_StringRepresentation6) {
1988
- _inherits(DateTime, _StringRepresentation6);
1986
+ var DateTime = /*#__PURE__*/function (_AsciiStringRepresent6) {
1987
+ _inherits(DateTime, _AsciiStringRepresent6);
1989
1988
 
1990
- var _super9 = _createSuper(DateTime);
1989
+ var _super10 = _createSuper(DateTime);
1991
1990
 
1992
1991
  function DateTime() {
1993
1992
  var _this8;
1994
1993
 
1995
1994
  _classCallCheck(this, DateTime);
1996
1995
 
1997
- _this8 = _super9.call(this, "DT");
1996
+ _this8 = _super10.call(this, "DT");
1998
1997
  _this8.maxLength = 26;
1999
- _this8.padByte = "20";
1998
+ _this8.padByte = 0x20;
2000
1999
  return _this8;
2001
2000
  }
2002
2001
 
2003
2002
  return _createClass(DateTime);
2004
- }(StringRepresentation);
2003
+ }(AsciiStringRepresentation);
2005
2004
 
2006
- var FloatingPointSingle = /*#__PURE__*/function (_ValueRepresentation4) {
2007
- _inherits(FloatingPointSingle, _ValueRepresentation4);
2005
+ var FloatingPointSingle = /*#__PURE__*/function (_ValueRepresentation5) {
2006
+ _inherits(FloatingPointSingle, _ValueRepresentation5);
2008
2007
 
2009
- var _super10 = _createSuper(FloatingPointSingle);
2008
+ var _super11 = _createSuper(FloatingPointSingle);
2010
2009
 
2011
2010
  function FloatingPointSingle() {
2012
2011
  var _this9;
2013
2012
 
2014
2013
  _classCallCheck(this, FloatingPointSingle);
2015
2014
 
2016
- _this9 = _super10.call(this, "FL");
2015
+ _this9 = _super11.call(this, "FL");
2017
2016
  _this9.maxLength = 4;
2018
- _this9.padByte = "00";
2017
+ _this9.padByte = 0;
2019
2018
  _this9.fixed = true;
2020
2019
  _this9.defaultValue = 0.0;
2021
2020
  return _this9;
@@ -2036,19 +2035,19 @@ var FloatingPointSingle = /*#__PURE__*/function (_ValueRepresentation4) {
2036
2035
  return FloatingPointSingle;
2037
2036
  }(ValueRepresentation);
2038
2037
 
2039
- var FloatingPointDouble = /*#__PURE__*/function (_ValueRepresentation5) {
2040
- _inherits(FloatingPointDouble, _ValueRepresentation5);
2038
+ var FloatingPointDouble = /*#__PURE__*/function (_ValueRepresentation6) {
2039
+ _inherits(FloatingPointDouble, _ValueRepresentation6);
2041
2040
 
2042
- var _super11 = _createSuper(FloatingPointDouble);
2041
+ var _super12 = _createSuper(FloatingPointDouble);
2043
2042
 
2044
2043
  function FloatingPointDouble() {
2045
2044
  var _this10;
2046
2045
 
2047
2046
  _classCallCheck(this, FloatingPointDouble);
2048
2047
 
2049
- _this10 = _super11.call(this, "FD");
2048
+ _this10 = _super12.call(this, "FD");
2050
2049
  _this10.maxLength = 8;
2051
- _this10.padByte = "00";
2050
+ _this10.padByte = 0;
2052
2051
  _this10.fixed = true;
2053
2052
  _this10.defaultValue = 0.0;
2054
2053
  return _this10;
@@ -2069,19 +2068,19 @@ var FloatingPointDouble = /*#__PURE__*/function (_ValueRepresentation5) {
2069
2068
  return FloatingPointDouble;
2070
2069
  }(ValueRepresentation);
2071
2070
 
2072
- var IntegerString = /*#__PURE__*/function (_StringRepresentation7) {
2073
- _inherits(IntegerString, _StringRepresentation7);
2071
+ var IntegerString = /*#__PURE__*/function (_AsciiStringRepresent7) {
2072
+ _inherits(IntegerString, _AsciiStringRepresent7);
2074
2073
 
2075
- var _super12 = _createSuper(IntegerString);
2074
+ var _super13 = _createSuper(IntegerString);
2076
2075
 
2077
2076
  function IntegerString() {
2078
2077
  var _this11;
2079
2078
 
2080
2079
  _classCallCheck(this, IntegerString);
2081
2080
 
2082
- _this11 = _super12.call(this, "IS");
2081
+ _this11 = _super13.call(this, "IS");
2083
2082
  _this11.maxLength = 12;
2084
- _this11.padByte = "20";
2083
+ _this11.padByte = 0x20;
2085
2084
  return _this11;
2086
2085
  }
2087
2086
 
@@ -2089,7 +2088,7 @@ var IntegerString = /*#__PURE__*/function (_StringRepresentation7) {
2089
2088
  key: "readBytes",
2090
2089
  value: function readBytes(stream, length) {
2091
2090
  var BACKSLASH = String.fromCharCode(0x5c);
2092
- var is = stream.readString(length).trim();
2091
+ var is = stream.readAsciiString(length).trim();
2093
2092
  is = is.replace(/[^0-9.\\\-+e]/gi, "");
2094
2093
 
2095
2094
  if (is.indexOf(BACKSLASH) !== -1) {
@@ -2122,75 +2121,73 @@ var IntegerString = /*#__PURE__*/function (_StringRepresentation7) {
2122
2121
  }]);
2123
2122
 
2124
2123
  return IntegerString;
2125
- }(StringRepresentation);
2124
+ }(AsciiStringRepresentation);
2126
2125
 
2127
- var LongString = /*#__PURE__*/function (_StringRepresentation8) {
2128
- _inherits(LongString, _StringRepresentation8);
2126
+ var LongString = /*#__PURE__*/function (_EncodedStringReprese) {
2127
+ _inherits(LongString, _EncodedStringReprese);
2129
2128
 
2130
- var _super13 = _createSuper(LongString);
2129
+ var _super14 = _createSuper(LongString);
2131
2130
 
2132
2131
  function LongString() {
2133
2132
  var _this13;
2134
2133
 
2135
2134
  _classCallCheck(this, LongString);
2136
2135
 
2137
- _this13 = _super13.call(this, "LO");
2136
+ _this13 = _super14.call(this, "LO");
2138
2137
  _this13.maxCharLength = 64;
2139
- _this13.padByte = "20";
2138
+ _this13.padByte = 0x20;
2140
2139
  return _this13;
2141
2140
  }
2142
2141
 
2143
2142
  _createClass(LongString, [{
2144
2143
  key: "readBytes",
2145
2144
  value: function readBytes(stream, length) {
2146
- //return this.readNullPaddedString(stream, length).trim();
2147
- return stream.readString(length).trim();
2145
+ return stream.readEncodedString(length).trim();
2148
2146
  }
2149
2147
  }]);
2150
2148
 
2151
2149
  return LongString;
2152
- }(StringRepresentation);
2150
+ }(EncodedStringRepresentation);
2153
2151
 
2154
- var LongText = /*#__PURE__*/function (_StringRepresentation9) {
2155
- _inherits(LongText, _StringRepresentation9);
2152
+ var LongText = /*#__PURE__*/function (_EncodedStringReprese2) {
2153
+ _inherits(LongText, _EncodedStringReprese2);
2156
2154
 
2157
- var _super14 = _createSuper(LongText);
2155
+ var _super15 = _createSuper(LongText);
2158
2156
 
2159
2157
  function LongText() {
2160
2158
  var _this14;
2161
2159
 
2162
2160
  _classCallCheck(this, LongText);
2163
2161
 
2164
- _this14 = _super14.call(this, "LT");
2162
+ _this14 = _super15.call(this, "LT");
2165
2163
  _this14.maxCharLength = 10240;
2166
- _this14.padByte = "20";
2164
+ _this14.padByte = 0x20;
2167
2165
  return _this14;
2168
2166
  }
2169
2167
 
2170
2168
  _createClass(LongText, [{
2171
2169
  key: "readBytes",
2172
2170
  value: function readBytes(stream, length) {
2173
- //return rtrim(this.readNullPaddedString(stream, length));
2174
- return rtrim(stream.readString(length));
2171
+ return rtrim(stream.readEncodedString(length));
2175
2172
  }
2176
2173
  }]);
2177
2174
 
2178
2175
  return LongText;
2179
- }(StringRepresentation);
2176
+ }(EncodedStringRepresentation);
2180
2177
 
2181
- var PersonName = /*#__PURE__*/function (_StringRepresentation10) {
2182
- _inherits(PersonName, _StringRepresentation10);
2178
+ var PersonName = /*#__PURE__*/function (_EncodedStringReprese3) {
2179
+ _inherits(PersonName, _EncodedStringReprese3);
2183
2180
 
2184
- var _super15 = _createSuper(PersonName);
2181
+ var _super16 = _createSuper(PersonName);
2185
2182
 
2186
2183
  function PersonName() {
2187
2184
  var _this15;
2188
2185
 
2189
2186
  _classCallCheck(this, PersonName);
2190
2187
 
2191
- _this15 = _super15.call(this, "PN");
2188
+ _this15 = _super16.call(this, "PN");
2192
2189
  _this15.maxLength = null;
2193
- _this15.padByte = "20";
2190
+ _this15.padByte = 0x20;
2194
2191
  return _this15;
2195
2192
  }
2196
2193
 
@@ -2225,54 +2222,52 @@ var PersonName = /*#__PURE__*/function (_StringRepresentation10) {
2225
2222
  }, {
2226
2223
  key: "readBytes",
2227
2224
  value: function readBytes(stream, length) {
2228
- //return rtrim(this.readNullPaddedString(stream, length));
2229
- return rtrim(stream.readString(length));
2225
+ return rtrim(stream.readEncodedString(length));
2230
2226
  }
2231
2227
  }]);
2232
2228
 
2233
2229
  return PersonName;
2234
- }(StringRepresentation);
2230
+ }(EncodedStringRepresentation);
2235
2231
 
2236
- var ShortString = /*#__PURE__*/function (_StringRepresentation11) {
2237
- _inherits(ShortString, _StringRepresentation11);
2232
+ var ShortString = /*#__PURE__*/function (_EncodedStringReprese4) {
2233
+ _inherits(ShortString, _EncodedStringReprese4);
2238
2234
 
2239
- var _super16 = _createSuper(ShortString);
2235
+ var _super17 = _createSuper(ShortString);
2240
2236
 
2241
2237
  function ShortString() {
2242
2238
  var _this16;
2243
2239
 
2244
2240
  _classCallCheck(this, ShortString);
2245
2241
 
2246
- _this16 = _super16.call(this, "SH");
2242
+ _this16 = _super17.call(this, "SH");
2247
2243
  _this16.maxCharLength = 16;
2248
- _this16.padByte = "20";
2244
+ _this16.padByte = 0x20;
2249
2245
  return _this16;
2250
2246
  }
2251
2247
 
2252
2248
  _createClass(ShortString, [{
2253
2249
  key: "readBytes",
2254
2250
  value: function readBytes(stream, length) {
2255
- //return this.readNullPaddedString(stream, length).trim();
2256
- return stream.readString(length).trim();
2251
+ return stream.readEncodedString(length).trim();
2257
2252
  }
2258
2253
  }]);
2259
2254
 
2260
2255
  return ShortString;
2261
- }(StringRepresentation);
2256
+ }(EncodedStringRepresentation);
2262
2257
 
2263
- var SignedLong = /*#__PURE__*/function (_ValueRepresentation6) {
2264
- _inherits(SignedLong, _ValueRepresentation6);
2258
+ var SignedLong = /*#__PURE__*/function (_ValueRepresentation7) {
2259
+ _inherits(SignedLong, _ValueRepresentation7);
2265
2260
 
2266
- var _super17 = _createSuper(SignedLong);
2261
+ var _super18 = _createSuper(SignedLong);
2267
2262
 
2268
2263
  function SignedLong() {
2269
2264
  var _this17;
2270
2265
 
2271
2266
  _classCallCheck(this, SignedLong);
2272
2267
 
2273
- _this17 = _super17.call(this, "SL");
2268
+ _this17 = _super18.call(this, "SL");
2274
2269
  _this17.maxLength = 4;
2275
- _this17.padByte = "00";
2270
+ _this17.padByte = 0;
2276
2271
  _this17.fixed = true;
2277
2272
  _this17.defaultValue = 0;
2278
2273
  return _this17;
@@ -2293,19 +2288,19 @@ var SignedLong = /*#__PURE__*/function (_ValueRepresentation6) {
2293
2288
  return SignedLong;
2294
2289
  }(ValueRepresentation);
2295
2290
 
2296
- var SequenceOfItems = /*#__PURE__*/function (_ValueRepresentation7) {
2297
- _inherits(SequenceOfItems, _ValueRepresentation7);
2291
+ var SequenceOfItems = /*#__PURE__*/function (_ValueRepresentation8) {
2292
+ _inherits(SequenceOfItems, _ValueRepresentation8);
2298
2293
 
2299
- var _super18 = _createSuper(SequenceOfItems);
2294
+ var _super19 = _createSuper(SequenceOfItems);
2300
2295
 
2301
2296
  function SequenceOfItems() {
2302
2297
  var _this18;
2303
2298
 
2304
2299
  _classCallCheck(this, SequenceOfItems);
2305
2300
 
2306
- _this18 = _super18.call(this, "SQ");
2301
+ _this18 = _super19.call(this, "SQ");
2307
2302
  _this18.maxLength = null;
2308
- _this18.padByte = "00";
2303
+ _this18.padByte = 0;
2309
2304
  _this18.noMultiple = true;
2310
2305
  return _this18;
2311
2306
  }
@@ -2449,20 +2444,20 @@ var SequenceOfItems = /*#__PURE__*/function (_ValueRepresentation7) {
2449
2444
  return SequenceOfItems;
2450
2445
  }(ValueRepresentation);
2451
2446
 
2452
- var SignedShort = /*#__PURE__*/function (_ValueRepresentation8) {
2453
- _inherits(SignedShort, _ValueRepresentation8);
2447
+ var SignedShort = /*#__PURE__*/function (_ValueRepresentation9) {
2448
+ _inherits(SignedShort, _ValueRepresentation9);
2454
2449
 
2455
- var _super19 = _createSuper(SignedShort);
2450
+ var _super20 = _createSuper(SignedShort);
2456
2451
 
2457
2452
  function SignedShort() {
2458
2453
  var _this19;
2459
2454
 
2460
2455
  _classCallCheck(this, SignedShort);
2461
2456
 
2462
- _this19 = _super19.call(this, "SS");
2457
+ _this19 = _super20.call(this, "SS");
2463
2458
  _this19.maxLength = 2;
2464
2459
  _this19.valueLength = 2;
2465
- _this19.padByte = "00";
2460
+ _this19.padByte = 0;
2466
2461
  _this19.fixed = true;
2467
2462
  _this19.defaultValue = 0;
2468
2463
  return _this19;
@@ -2483,126 +2478,124 @@ var SignedShort = /*#__PURE__*/function (_ValueRepresentation8) {
2483
2478
  return SignedShort;
2484
2479
  }(ValueRepresentation);
2485
2480
 
2486
- var ShortText = /*#__PURE__*/function (_StringRepresentation12) {
2487
- _inherits(ShortText, _StringRepresentation12);
2481
+ var ShortText = /*#__PURE__*/function (_EncodedStringReprese5) {
2482
+ _inherits(ShortText, _EncodedStringReprese5);
2488
2483
 
2489
- var _super20 = _createSuper(ShortText);
2484
+ var _super21 = _createSuper(ShortText);
2490
2485
 
2491
2486
  function ShortText() {
2492
2487
  var _this20;
2493
2488
 
2494
2489
  _classCallCheck(this, ShortText);
2495
2490
 
2496
- _this20 = _super20.call(this, "ST");
2491
+ _this20 = _super21.call(this, "ST");
2497
2492
  _this20.maxCharLength = 1024;
2498
- _this20.padByte = "20";
2493
+ _this20.padByte = 0x20;
2499
2494
  return _this20;
2500
2495
  }
2501
2496
 
2502
2497
  _createClass(ShortText, [{
2503
2498
  key: "readBytes",
2504
2499
  value: function readBytes(stream, length) {
2505
- //return rtrim(this.readNullPaddedString(stream, length));
2506
- return rtrim(stream.readString(length));
2500
+ return rtrim(stream.readEncodedString(length));
2507
2501
  }
2508
2502
  }]);
2509
2503
 
2510
2504
  return ShortText;
2511
- }(StringRepresentation);
2505
+ }(EncodedStringRepresentation);
2512
2506
 
2513
- var TimeValue = /*#__PURE__*/function (_StringRepresentation13) {
2514
- _inherits(TimeValue, _StringRepresentation13);
2507
+ var TimeValue = /*#__PURE__*/function (_AsciiStringRepresent8) {
2508
+ _inherits(TimeValue, _AsciiStringRepresent8);
2515
2509
 
2516
- var _super21 = _createSuper(TimeValue);
2510
+ var _super22 = _createSuper(TimeValue);
2517
2511
 
2518
2512
  function TimeValue() {
2519
2513
  var _this21;
2520
2514
 
2521
2515
  _classCallCheck(this, TimeValue);
2522
2516
 
2523
- _this21 = _super21.call(this, "TM");
2517
+ _this21 = _super22.call(this, "TM");
2524
2518
  _this21.maxLength = 14;
2525
- _this21.padByte = "20";
2519
+ _this21.padByte = 0x20;
2526
2520
  return _this21;
2527
2521
  }
2528
2522
 
2529
2523
  _createClass(TimeValue, [{
2530
2524
  key: "readBytes",
2531
2525
  value: function readBytes(stream, length) {
2532
- return rtrim(stream.readString(length));
2526
+ return rtrim(stream.readAsciiString(length));
2533
2527
  }
2534
2528
  }]);
2535
2529
 
2536
2530
  return TimeValue;
2537
- }(StringRepresentation);
2531
+ }(AsciiStringRepresentation);
2538
2532
 
2539
- var UnlimitedCharacters = /*#__PURE__*/function (_StringRepresentation14) {
2540
- _inherits(UnlimitedCharacters, _StringRepresentation14);
2533
+ var UnlimitedCharacters = /*#__PURE__*/function (_EncodedStringReprese6) {
2534
+ _inherits(UnlimitedCharacters, _EncodedStringReprese6);
2541
2535
 
2542
- var _super22 = _createSuper(UnlimitedCharacters);
2536
+ var _super23 = _createSuper(UnlimitedCharacters);
2543
2537
 
2544
2538
  function UnlimitedCharacters() {
2545
2539
  var _this22;
2546
2540
 
2547
2541
  _classCallCheck(this, UnlimitedCharacters);
2548
2542
 
2549
- _this22 = _super22.call(this, "UC");
2543
+ _this22 = _super23.call(this, "UC");
2550
2544
  _this22.maxLength = null;
2551
2545
  _this22.multi = true;
2552
- _this22.padByte = "20";
2546
+ _this22.padByte = 0x20;
2553
2547
  return _this22;
2554
2548
  }
2555
2549
 
2556
2550
  _createClass(UnlimitedCharacters, [{
2557
2551
  key: "readBytes",
2558
2552
  value: function readBytes(stream, length) {
2559
- return rtrim(stream.readString(length));
2553
+ return rtrim(stream.readEncodedString(length));
2560
2554
  }
2561
2555
  }]);
2562
2556
 
2563
2557
  return UnlimitedCharacters;
2564
- }(StringRepresentation);
2558
+ }(EncodedStringRepresentation);
2565
2559
 
2566
- var UnlimitedText = /*#__PURE__*/function (_StringRepresentation15) {
2567
- _inherits(UnlimitedText, _StringRepresentation15);
2560
+ var UnlimitedText = /*#__PURE__*/function (_EncodedStringReprese7) {
2561
+ _inherits(UnlimitedText, _EncodedStringReprese7);
2568
2562
 
2569
- var _super23 = _createSuper(UnlimitedText);
2563
+ var _super24 = _createSuper(UnlimitedText);
2570
2564
 
2571
2565
  function UnlimitedText() {
2572
2566
  var _this23;
2573
2567
 
2574
2568
  _classCallCheck(this, UnlimitedText);
2575
2569
 
2576
- _this23 = _super23.call(this, "UT");
2570
+ _this23 = _super24.call(this, "UT");
2577
2571
  _this23.maxLength = null;
2578
- _this23.padByte = "20";
2572
+ _this23.padByte = 0x20;
2579
2573
  return _this23;
2580
2574
  }
2581
2575
 
2582
2576
  _createClass(UnlimitedText, [{
2583
2577
  key: "readBytes",
2584
2578
  value: function readBytes(stream, length) {
2585
- //return this.readNullPaddedString(stream, length);
2586
- return rtrim(stream.readString(length));
2579
+ return rtrim(stream.readEncodedString(length));
2587
2580
  }
2588
2581
  }]);
2589
2582
 
2590
2583
  return UnlimitedText;
2591
- }(StringRepresentation);
2584
+ }(EncodedStringRepresentation);
2592
2585
 
2593
- var UnsignedShort = /*#__PURE__*/function (_ValueRepresentation9) {
2594
- _inherits(UnsignedShort, _ValueRepresentation9);
2586
+ var UnsignedShort = /*#__PURE__*/function (_ValueRepresentation10) {
2587
+ _inherits(UnsignedShort, _ValueRepresentation10);
2595
2588
 
2596
- var _super24 = _createSuper(UnsignedShort);
2589
+ var _super25 = _createSuper(UnsignedShort);
2597
2590
 
2598
2591
  function UnsignedShort() {
2599
2592
  var _this24;
2600
2593
 
2601
2594
  _classCallCheck(this, UnsignedShort);
2602
2595
 
2603
- _this24 = _super24.call(this, "US");
2596
+ _this24 = _super25.call(this, "US");
2604
2597
  _this24.maxLength = 2;
2605
- _this24.padByte = "00";
2598
+ _this24.padByte = 0;
2606
2599
  _this24.fixed = true;
2607
2600
  _this24.defaultValue = 0;
2608
2601
  return _this24;
@@ -2623,19 +2616,19 @@ var UnsignedShort = /*#__PURE__*/function (_ValueRepresentation9) {
2623
2616
  return UnsignedShort;
2624
2617
  }(ValueRepresentation);
2625
2618
 
2626
- var UnsignedLong = /*#__PURE__*/function (_ValueRepresentation10) {
2627
- _inherits(UnsignedLong, _ValueRepresentation10);
2619
+ var UnsignedLong = /*#__PURE__*/function (_ValueRepresentation11) {
2620
+ _inherits(UnsignedLong, _ValueRepresentation11);
2628
2621
 
2629
- var _super25 = _createSuper(UnsignedLong);
2622
+ var _super26 = _createSuper(UnsignedLong);
2630
2623
 
2631
2624
  function UnsignedLong() {
2632
2625
  var _this25;
2633
2626
 
2634
2627
  _classCallCheck(this, UnsignedLong);
2635
2628
 
2636
- _this25 = _super25.call(this, "UL");
2629
+ _this25 = _super26.call(this, "UL");
2637
2630
  _this25.maxLength = 4;
2638
- _this25.padByte = "00";
2631
+ _this25.padByte = 0;
2639
2632
  _this25.fixed = true;
2640
2633
  _this25.defaultValue = 0;
2641
2634
  return _this25;
@@ -2656,19 +2649,19 @@ var UnsignedLong = /*#__PURE__*/function (_ValueRepresentation10) {
2656
2649
  return UnsignedLong;
2657
2650
  }(ValueRepresentation);
2658
2651
 
2659
- var UniqueIdentifier = /*#__PURE__*/function (_StringRepresentation16) {
2660
- _inherits(UniqueIdentifier, _StringRepresentation16);
2652
+ var UniqueIdentifier = /*#__PURE__*/function (_AsciiStringRepresent9) {
2653
+ _inherits(UniqueIdentifier, _AsciiStringRepresent9);
2661
2654
 
2662
- var _super26 = _createSuper(UniqueIdentifier);
2655
+ var _super27 = _createSuper(UniqueIdentifier);
2663
2656
 
2664
2657
  function UniqueIdentifier() {
2665
2658
  var _this26;
2666
2659
 
2667
2660
  _classCallCheck(this, UniqueIdentifier);
2668
2661
 
2669
- _this26 = _super26.call(this, "UI");
2662
+ _this26 = _super27.call(this, "UI");
2670
2663
  _this26.maxLength = 64;
2671
- _this26.padByte = "00";
2664
+ _this26.padByte = 0;
2672
2665
  return _this26;
2673
2666
  }
2674
2667
 
@@ -2696,47 +2689,47 @@ var UniqueIdentifier = /*#__PURE__*/function (_StringRepresentation16) {
2696
2689
  }]);
2697
2690
 
2698
2691
  return UniqueIdentifier;
2699
- }(StringRepresentation);
2692
+ }(AsciiStringRepresentation);
2700
2693
 
2701
- var UniversalResource = /*#__PURE__*/function (_StringRepresentation17) {
2702
- _inherits(UniversalResource, _StringRepresentation17);
2694
+ var UniversalResource = /*#__PURE__*/function (_AsciiStringRepresent10) {
2695
+ _inherits(UniversalResource, _AsciiStringRepresent10);
2703
2696
 
2704
- var _super27 = _createSuper(UniversalResource);
2697
+ var _super28 = _createSuper(UniversalResource);
2705
2698
 
2706
2699
  function UniversalResource() {
2707
2700
  var _this27;
2708
2701
 
2709
2702
  _classCallCheck(this, UniversalResource);
2710
2703
 
2711
- _this27 = _super27.call(this, "UR");
2704
+ _this27 = _super28.call(this, "UR");
2712
2705
  _this27.maxLength = null;
2713
- _this27.padByte = "20";
2706
+ _this27.padByte = 0x20;
2714
2707
  return _this27;
2715
2708
  }
2716
2709
 
2717
2710
  _createClass(UniversalResource, [{
2718
2711
  key: "readBytes",
2719
2712
  value: function readBytes(stream, length) {
2720
- return stream.readString(length);
2713
+ return stream.readAsciiString(length);
2721
2714
  }
2722
2715
  }]);
2723
2716
 
2724
2717
  return UniversalResource;
2725
- }(StringRepresentation);
2718
+ }(AsciiStringRepresentation);
2726
2719
 
2727
2720
  var UnknownValue = /*#__PURE__*/function (_BinaryRepresentation) {
2728
2721
  _inherits(UnknownValue, _BinaryRepresentation);
2729
2722
 
2730
- var _super28 = _createSuper(UnknownValue);
2723
+ var _super29 = _createSuper(UnknownValue);
2731
2724
 
2732
2725
  function UnknownValue() {
2733
2726
  var _this28;
2734
2727
 
2735
2728
  _classCallCheck(this, UnknownValue);
2736
2729
 
2737
- _this28 = _super28.call(this, "UN");
2730
+ _this28 = _super29.call(this, "UN");
2738
2731
  _this28.maxLength = null;
2739
- _this28.padByte = "00";
2732
+ _this28.padByte = 0;
2740
2733
  _this28.noMultiple = true;
2741
2734
  return _this28;
2742
2735
  }
@@ -2747,16 +2740,16 @@ var UnknownValue = /*#__PURE__*/function (_BinaryRepresentation) {
2747
2740
  var OtherWordString = /*#__PURE__*/function (_BinaryRepresentation2) {
2748
2741
  _inherits(OtherWordString, _BinaryRepresentation2);
2749
2742
 
2750
- var _super29 = _createSuper(OtherWordString);
2743
+ var _super30 = _createSuper(OtherWordString);
2751
2744
 
2752
2745
  function OtherWordString() {
2753
2746
  var _this29;
2754
2747
 
2755
2748
  _classCallCheck(this, OtherWordString);
2756
2749
 
2757
- _this29 = _super29.call(this, "OW");
2750
+ _this29 = _super30.call(this, "OW");
2758
2751
  _this29.maxLength = null;
2759
- _this29.padByte = "00";
2752
+ _this29.padByte = 0;
2760
2753
  _this29.noMultiple = true;
2761
2754
  return _this29;
2762
2755
  }
@@ -2767,16 +2760,16 @@ var OtherWordString = /*#__PURE__*/function (_BinaryRepresentation2) {
2767
2760
  var OtherByteString = /*#__PURE__*/function (_BinaryRepresentation3) {
2768
2761
  _inherits(OtherByteString, _BinaryRepresentation3);
2769
2762
 
2770
- var _super30 = _createSuper(OtherByteString);
2763
+ var _super31 = _createSuper(OtherByteString);
2771
2764
 
2772
2765
  function OtherByteString() {
2773
2766
  var _this30;
2774
2767
 
2775
2768
  _classCallCheck(this, OtherByteString);
2776
2769
 
2777
- _this30 = _super30.call(this, "OB");
2770
+ _this30 = _super31.call(this, "OB");
2778
2771
  _this30.maxLength = null;
2779
- _this30.padByte = "00";
2772
+ _this30.padByte = 0;
2780
2773
  _this30.noMultiple = true;
2781
2774
  return _this30;
2782
2775
  }
@@ -2787,16 +2780,16 @@ var OtherByteString = /*#__PURE__*/function (_BinaryRepresentation3) {
2787
2780
  var OtherDoubleString = /*#__PURE__*/function (_BinaryRepresentation4) {
2788
2781
  _inherits(OtherDoubleString, _BinaryRepresentation4);
2789
2782
 
2790
- var _super31 = _createSuper(OtherDoubleString);
2783
+ var _super32 = _createSuper(OtherDoubleString);
2791
2784
 
2792
2785
  function OtherDoubleString() {
2793
2786
  var _this31;
2794
2787
 
2795
2788
  _classCallCheck(this, OtherDoubleString);
2796
2789
 
2797
- _this31 = _super31.call(this, "OD");
2790
+ _this31 = _super32.call(this, "OD");
2798
2791
  _this31.maxLength = null;
2799
- _this31.padByte = "00";
2792
+ _this31.padByte = 0;
2800
2793
  _this31.noMultiple = true;
2801
2794
  return _this31;
2802
2795
  }
@@ -2807,22 +2800,56 @@ var OtherDoubleString = /*#__PURE__*/function (_BinaryRepresentation4) {
2807
2800
  var OtherFloatString = /*#__PURE__*/function (_BinaryRepresentation5) {
2808
2801
  _inherits(OtherFloatString, _BinaryRepresentation5);
2809
2802
 
2810
- var _super32 = _createSuper(OtherFloatString);
2803
+ var _super33 = _createSuper(OtherFloatString);
2811
2804
 
2812
2805
  function OtherFloatString() {
2813
2806
  var _this32;
2814
2807
 
2815
2808
  _classCallCheck(this, OtherFloatString);
2816
2809
 
2817
- _this32 = _super32.call(this, "OF");
2810
+ _this32 = _super33.call(this, "OF");
2818
2811
  _this32.maxLength = null;
2819
- _this32.padByte = "00";
2812
+ _this32.padByte = 0;
2820
2813
  _this32.noMultiple = true;
2821
2814
  return _this32;
2822
2815
  }
2823
2816
 
2824
2817
  return _createClass(OtherFloatString);
2825
- }(BinaryRepresentation);
2818
+ }(BinaryRepresentation); // these VR instances are precreate and are reused for each requested vr/tag
2819
+
2820
+
2821
+ var VRinstances = {
2822
+ AE: new ApplicationEntity(),
2823
+ AS: new AgeString(),
2824
+ AT: new AttributeTag(),
2825
+ CS: new CodeString(),
2826
+ DA: new DateValue(),
2827
+ DS: new DecimalString(),
2828
+ DT: new DateTime(),
2829
+ FL: new FloatingPointSingle(),
2830
+ FD: new FloatingPointDouble(),
2831
+ IS: new IntegerString(),
2832
+ LO: new LongString(),
2833
+ LT: new LongText(),
2834
+ OB: new OtherByteString(),
2835
+ OD: new OtherDoubleString(),
2836
+ OF: new OtherFloatString(),
2837
+ OW: new OtherWordString(),
2838
+ PN: new PersonName(),
2839
+ SH: new ShortString(),
2840
+ SL: new SignedLong(),
2841
+ SQ: new SequenceOfItems(),
2842
+ SS: new SignedShort(),
2843
+ ST: new ShortText(),
2844
+ TM: new TimeValue(),
2845
+ UC: new UnlimitedCharacters(),
2846
+ UI: new UniqueIdentifier(),
2847
+ UL: new UnsignedLong(),
2848
+ UN: new UnknownValue(),
2849
+ UR: new UniversalResource(),
2850
+ US: new UnsignedShort(),
2851
+ UT: new UnlimitedText()
2852
+ };
2826
2853
 
2827
2854
  var IMPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2";
2828
2855
  var EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1";
@@ -2911,12 +2938,12 @@ var Tag = /*#__PURE__*/function () {
2911
2938
  written += 4;
2912
2939
  } else {
2913
2940
  if (vr.isExplicit()) {
2914
- stream.writeString(vr.type);
2915
- stream.writeHex("0000");
2941
+ stream.writeAsciiString(vr.type);
2942
+ stream.writeUint16(0);
2916
2943
  stream.writeUint32(valueLength);
2917
2944
  written += 8;
2918
2945
  } else {
2919
- stream.writeString(vr.type);
2946
+ stream.writeAsciiString(vr.type);
2920
2947
  stream.writeUint16(valueLength);
2921
2948
  written += 4;
2922
2949
  }
@@ -3388,6 +3415,10 @@ var IMPLICIT_LITTLE_ENDIAN$1 = "1.2.840.10008.1.2";
3388
3415
  var EXPLICIT_LITTLE_ENDIAN$1 = "1.2.840.10008.1.2.1";
3389
3416
  var EXPLICIT_BIG_ENDIAN = "1.2.840.10008.1.2.2";
3390
3417
  var singleVRs$1 = ["SQ", "OF", "OW", "OB", "UN", "LT"];
3418
+ var encodingMapping = {
3419
+ "iso-ir-192": "utf-8",
3420
+ "": "latin1"
3421
+ };
3391
3422
  var encapsulatedSyntaxes = ["1.2.840.10008.1.2.4.50", "1.2.840.10008.1.2.4.51", "1.2.840.10008.1.2.4.57", "1.2.840.10008.1.2.4.70", "1.2.840.10008.1.2.4.80", "1.2.840.10008.1.2.4.81", "1.2.840.10008.1.2.4.90", "1.2.840.10008.1.2.4.91", "1.2.840.10008.1.2.4.92", "1.2.840.10008.1.2.4.93", "1.2.840.10008.1.2.4.94", "1.2.840.10008.1.2.4.95", "1.2.840.10008.1.2.5", "1.2.840.10008.1.2.6.1", "1.2.840.10008.1.2.4.100", "1.2.840.10008.1.2.4.102", "1.2.840.10008.1.2.4.103"];
3392
3423
 
3393
3424
  var DicomMessage = /*#__PURE__*/function () {
@@ -3435,6 +3466,30 @@ var DicomMessage = /*#__PURE__*/function () {
3435
3466
  var readInfo = DicomMessage._readTag(bufferStream, syntax, options);
3436
3467
 
3437
3468
  var cleanTagString = readInfo.tag.toCleanString();
3469
+
3470
+ if (cleanTagString === "00080005") {
3471
+ if (readInfo.values.length > 0) {
3472
+ var coding = readInfo.values[0];
3473
+ coding = coding.replaceAll("_", "-").replaceAll(" ", "-").toLowerCase();
3474
+
3475
+ if (coding in encodingMapping) {
3476
+ coding = encodingMapping[coding];
3477
+ }
3478
+
3479
+ try {
3480
+ bufferStream.setDecoder(new TextDecoder(coding));
3481
+ } catch (error) {
3482
+ console.warn(error);
3483
+ }
3484
+ }
3485
+
3486
+ if (readInfo.values.length > 1) {
3487
+ console.warn("multiple encodings not supported, using first encoding!", readInfo.values);
3488
+ }
3489
+
3490
+ readInfo.values = ["ISO_IR 192"]; // change SpecificCharacterSet to UTF-8
3491
+ }
3492
+
3438
3493
  dict[cleanTagString] = {
3439
3494
  vr: readInfo.vr.type,
3440
3495
  Value: readInfo.values
@@ -3485,7 +3540,7 @@ var DicomMessage = /*#__PURE__*/function () {
3485
3540
  stream.reset();
3486
3541
  stream.increment(128);
3487
3542
 
3488
- if (stream.readString(4) !== "DICM") {
3543
+ if (stream.readAsciiString(4) !== "DICM") {
3489
3544
  throw new Error("Invalid a dicom file");
3490
3545
  }
3491
3546
 
@@ -3579,7 +3634,7 @@ var DicomMessage = /*#__PURE__*/function () {
3579
3634
 
3580
3635
  vr = ValueRepresentation.createByTypeString(vrType);
3581
3636
  } else {
3582
- vrType = stream.readString(2);
3637
+ vrType = stream.readVR();
3583
3638
  vr = ValueRepresentation.createByTypeString(vrType);
3584
3639
 
3585
3640
  if (vr.isExplicit()) {
@@ -3664,8 +3719,8 @@ var DicomDict = /*#__PURE__*/function () {
3664
3719
  };
3665
3720
  var metaSyntax = EXPLICIT_LITTLE_ENDIAN$2;
3666
3721
  var fileStream = new WriteBufferStream(4096, true);
3667
- fileStream.writeHex("00".repeat(128));
3668
- fileStream.writeString("DICM");
3722
+ fileStream.writeUint8Repeat(0, 128);
3723
+ fileStream.writeAsciiString("DICM");
3669
3724
  var metaStream = new WriteBufferStream(1024);
3670
3725
 
3671
3726
  if (!this.meta["00020010"]) {