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.js CHANGED
@@ -800,30 +800,6 @@
800
800
  };
801
801
  }
802
802
 
803
- //http://jonisalonen.com/2012/from-utf-16-to-utf-8-in-javascript/
804
- function toUTF8Array(str) {
805
- var utf8 = [];
806
-
807
- for (var i = 0; i < str.length; i++) {
808
- var charcode = str.charCodeAt(i);
809
- if (charcode < 0x80) utf8.push(charcode);else if (charcode < 0x800) {
810
- utf8.push(0xc0 | charcode >> 6, 0x80 | charcode & 0x3f);
811
- } else if (charcode < 0xd800 || charcode >= 0xe000) {
812
- utf8.push(0xe0 | charcode >> 12, 0x80 | charcode >> 6 & 0x3f, 0x80 | charcode & 0x3f);
813
- } // surrogate pair
814
- else {
815
- i++; // UTF-16 encodes 0x10000-0x10FFFF by
816
- // subtracting 0x10000 and splitting the
817
- // 20 bits of 0x0-0xFFFFF into two halves
818
-
819
- charcode = 0x10000 + ((charcode & 0x3ff) << 10 | str.charCodeAt(i) & 0x3ff);
820
- utf8.push(0xf0 | charcode >> 18, 0x80 | charcode >> 12 & 0x3f, 0x80 | charcode >> 6 & 0x3f, 0x80 | charcode & 0x3f);
821
- }
822
- }
823
-
824
- return utf8;
825
- }
826
-
827
803
  function toInt(val) {
828
804
  if (isNaN(val)) {
829
805
  throw new Error("Not a number: " + val);
@@ -854,6 +830,7 @@
854
830
  this.offset = 0;
855
831
  this.isLittleEndian = littleEndian || false;
856
832
  this.size = 0;
833
+ this.encoder = new TextEncoder("utf-8");
857
834
  }
858
835
 
859
836
  _createClass(BufferStream, [{
@@ -868,6 +845,18 @@
868
845
  this.view.setUint8(this.offset, toInt(value));
869
846
  return this.increment(1);
870
847
  }
848
+ }, {
849
+ key: "writeUint8Repeat",
850
+ value: function writeUint8Repeat(value, count) {
851
+ var v = toInt(value);
852
+ this.checkSize(count);
853
+
854
+ for (var i = 0; i < count; i++) {
855
+ this.view.setUint8(this.offset + i, v);
856
+ }
857
+
858
+ return this.increment(count);
859
+ }
871
860
  }, {
872
861
  key: "writeInt8",
873
862
  value: function writeInt8(value) {
@@ -928,48 +917,27 @@
928
917
  return this.increment(8);
929
918
  }
930
919
  }, {
931
- key: "writeString",
932
- value: function writeString(value) {
933
- value = value || "";
934
- var utf8 = toUTF8Array(value),
935
- bytelen = utf8.length;
936
- this.checkSize(bytelen);
937
- var startOffset = this.offset;
938
-
939
- for (var i = 0; i < bytelen; i++) {
940
- this.view.setUint8(startOffset, utf8[i]);
941
- startOffset++;
942
- }
943
-
944
- return this.increment(bytelen);
920
+ key: "writeUTF8String",
921
+ value: function writeUTF8String(value) {
922
+ var encodedString = this.encoder.encode(value);
923
+ this.checkSize(encodedString.byteLength);
924
+ new Uint8Array(this.buffer).set(encodedString, this.offset);
925
+ return this.increment(encodedString.byteLength);
945
926
  }
946
927
  }, {
947
- key: "writeHex",
948
- value: function writeHex(value) {
949
- var len = value.length,
950
- blen = len / 2,
951
- startOffset = this.offset;
952
- this.checkSize(blen);
953
-
954
- for (var i = 0; i < len; i += 2) {
955
- var code = parseInt(value[i], 16),
956
- nextCode;
957
-
958
- if (i == len - 1) {
959
- nextCode = null;
960
- } else {
961
- nextCode = parseInt(value[i + 1], 16);
962
- }
963
-
964
- if (nextCode !== null) {
965
- code = code << 4 | nextCode;
966
- }
928
+ key: "writeAsciiString",
929
+ value: function writeAsciiString(value) {
930
+ value = value || "";
931
+ var len = value.length;
932
+ this.checkSize(len);
933
+ var startOffset = this.offset;
967
934
 
968
- this.view.setUint8(startOffset, code);
969
- startOffset++;
935
+ for (var i = 0; i < len; i++) {
936
+ var charcode = value.charCodeAt(i);
937
+ this.view.setUint8(startOffset + i, charcode);
970
938
  }
971
939
 
972
- return this.increment(blen);
940
+ return this.increment(len);
973
941
  }
974
942
  }, {
975
943
  key: "readUint32",
@@ -992,6 +960,11 @@
992
960
  this.increment(1);
993
961
  return val;
994
962
  }
963
+ }, {
964
+ key: "peekUint8",
965
+ value: function peekUint8(offset) {
966
+ return this.view.getUint8(this.offset + offset);
967
+ }
995
968
  }, {
996
969
  key: "readUint8Array",
997
970
  value: function readUint8Array(length) {
@@ -1042,9 +1015,9 @@
1042
1015
  return val;
1043
1016
  }
1044
1017
  }, {
1045
- key: "readString",
1046
- value: function readString(length) {
1047
- var chars = [];
1018
+ key: "readAsciiString",
1019
+ value: function readAsciiString(length) {
1020
+ var result = "";
1048
1021
  var start = this.offset;
1049
1022
  var end = this.offset + length;
1050
1023
 
@@ -1053,11 +1026,30 @@
1053
1026
  }
1054
1027
 
1055
1028
  for (var i = start; i < end; ++i) {
1056
- chars.push(String.fromCharCode(this.view.getUint8(i)));
1057
- this.increment(1);
1029
+ result += String.fromCharCode(this.view.getUint8(i));
1030
+ }
1031
+
1032
+ this.increment(end - start);
1033
+ return result;
1034
+ }
1035
+ }, {
1036
+ key: "readVR",
1037
+ value: function readVR() {
1038
+ var vr = String.fromCharCode(this.view.getUint8(this.offset)) + String.fromCharCode(this.view.getUint8(this.offset + 1));
1039
+ this.increment(2);
1040
+ return vr;
1041
+ }
1042
+ }, {
1043
+ key: "readEncodedString",
1044
+ value: function readEncodedString(length) {
1045
+ if (this.offset + length >= this.buffer.byteLength) {
1046
+ length = this.buffer.byteLength - this.offset;
1058
1047
  }
1059
1048
 
1060
- return chars.join("");
1049
+ var view = new DataView(this.buffer, this.offset, length);
1050
+ var result = this.decoder.decode(view);
1051
+ this.increment(length);
1052
+ return result;
1061
1053
  }
1062
1054
  }, {
1063
1055
  key: "readHex",
@@ -1194,10 +1186,16 @@
1194
1186
  _this.noCopy = options.noCopy;
1195
1187
  _this.startOffset = _this.offset;
1196
1188
  _this.endOffset = _this.size;
1189
+ _this.decoder = new TextDecoder("latin1");
1197
1190
  return _this;
1198
1191
  }
1199
1192
 
1200
1193
  _createClass(ReadBufferStream, [{
1194
+ key: "setDecoder",
1195
+ value: function setDecoder(decoder) {
1196
+ this.decoder = decoder;
1197
+ }
1198
+ }, {
1201
1199
  key: "getBuffer",
1202
1200
  value: function getBuffer(start, end) {
1203
1201
  if (this.noCopy) {
@@ -1211,24 +1209,6 @@
1211
1209
 
1212
1210
  return this.buffer.slice(start, end);
1213
1211
  }
1214
- }, {
1215
- key: "readString",
1216
- value: function readString(length) {
1217
- var chars = [];
1218
- var start = this.offset;
1219
- var end = this.offset + length;
1220
-
1221
- if (end >= this.endOffset) {
1222
- end = this.endOffset;
1223
- }
1224
-
1225
- for (var i = start; i < end; ++i) {
1226
- chars.push(String.fromCharCode(this.view.getUint8(i)));
1227
- this.increment(1);
1228
- }
1229
-
1230
- return chars.join("");
1231
- }
1232
1212
  }, {
1233
1213
  key: "reset",
1234
1214
  value: function reset() {
@@ -1250,6 +1230,11 @@
1250
1230
  value: function writeUint8(value) {
1251
1231
  throw new Error(value, "writeUint8 not implemented");
1252
1232
  }
1233
+ }, {
1234
+ key: "writeUint8Repeat",
1235
+ value: function writeUint8Repeat(value, count) {
1236
+ throw new Error(value, "writeUint8Repeat not implemented");
1237
+ }
1253
1238
  }, {
1254
1239
  key: "writeInt8",
1255
1240
  value: function writeInt8(value) {
@@ -1291,14 +1276,14 @@
1291
1276
  throw new Error(value, "writeDouble not implemented");
1292
1277
  }
1293
1278
  }, {
1294
- key: "writeString",
1295
- value: function writeString(value) {
1296
- throw new Error(value, "writeString not implemented");
1279
+ key: "writeAsciiString",
1280
+ value: function writeAsciiString(value) {
1281
+ throw new Error(value, "writeAsciiString not implemented");
1297
1282
  }
1298
1283
  }, {
1299
- key: "writeHex",
1300
- value: function writeHex(value) {
1301
- throw new Error(value, "writeHex not implemented");
1284
+ key: "writeUTF8String",
1285
+ value: function writeUTF8String(value) {
1286
+ throw new Error(value, "writeUTF8String not implemented");
1302
1287
  }
1303
1288
  }, {
1304
1289
  key: "checkSize",
@@ -1357,22 +1342,25 @@
1357
1342
 
1358
1343
  this.type = type;
1359
1344
  this.multi = false;
1345
+ this._isBinary = binaryVRs.indexOf(this.type) != -1;
1346
+ this._allowMultiple = !this._isBinary && singleVRs.indexOf(this.type) == -1;
1347
+ this._isExplicit = explicitVRs.indexOf(this.type) != -1;
1360
1348
  }
1361
1349
 
1362
1350
  _createClass(ValueRepresentation, [{
1363
1351
  key: "isBinary",
1364
1352
  value: function isBinary() {
1365
- return binaryVRs.indexOf(this.type) != -1;
1353
+ return this._isBinary;
1366
1354
  }
1367
1355
  }, {
1368
1356
  key: "allowMultiple",
1369
1357
  value: function allowMultiple() {
1370
- return !this.isBinary() && singleVRs.indexOf(this.type) == -1;
1358
+ return this._allowMultiple;
1371
1359
  }
1372
1360
  }, {
1373
1361
  key: "isExplicit",
1374
1362
  value: function isExplicit() {
1375
- return explicitVRs.indexOf(this.type) != -1;
1363
+ return this._isExplicit;
1376
1364
  }
1377
1365
  }, {
1378
1366
  key: "read",
@@ -1387,34 +1375,19 @@
1387
1375
  }, {
1388
1376
  key: "readBytes",
1389
1377
  value: function readBytes(stream, length) {
1390
- return stream.readString(length);
1378
+ return stream.readAsciiString(length);
1391
1379
  }
1392
1380
  }, {
1393
1381
  key: "readNullPaddedString",
1394
1382
  value: function readNullPaddedString(stream, length) {
1395
1383
  if (!length) return "";
1396
- var str = stream.readString(length - 1);
1397
1384
 
1398
- if (stream.readUint8() != 0) {
1399
- stream.increment(-1);
1400
- str += stream.readString(1);
1401
- }
1402
-
1403
- return str;
1404
- }
1405
- }, {
1406
- key: "writeFilledString",
1407
- value: function writeFilledString(stream, value, length) {
1408
- if (length < this.maxLength && length >= 0) {
1409
- var written = 0;
1410
- if (length > 0) written += stream.writeString(value);
1411
- var zeroLength = this.maxLength - length;
1412
- written += stream.writeHex(this.fillWith.repeat(zeroLength));
1413
- return written;
1414
- } else if (length == this.maxLength) {
1415
- return stream.writeString(value);
1385
+ if (stream.peekUint8(length - 1) !== 0) {
1386
+ return stream.readAsciiString(length);
1416
1387
  } else {
1417
- throw "Length mismatch";
1388
+ var val = stream.readAsciiString(length - 1);
1389
+ stream.increment(1);
1390
+ return val;
1418
1391
  }
1419
1392
  }
1420
1393
  }, {
@@ -1423,7 +1396,7 @@
1423
1396
  var args = Array.from(arguments);
1424
1397
 
1425
1398
  if (args[2] === null || args[2] === "" || args[2] === undefined) {
1426
- return [stream.writeString("")];
1399
+ return [stream.writeAsciiString("")];
1427
1400
  } else {
1428
1401
  var written = [],
1429
1402
  valueArgs = args.slice(2),
@@ -1436,7 +1409,7 @@
1436
1409
  var self = this;
1437
1410
  valueArgs[0].forEach(function (v, k) {
1438
1411
  if (self.allowMultiple() && k > 0) {
1439
- stream.writeHex("5C"); //byteCount++;
1412
+ stream.writeUint8(0x5c);
1440
1413
  }
1441
1414
 
1442
1415
  var singularArgs = [v].concat(valueArgs.slice(1));
@@ -1498,7 +1471,7 @@
1498
1471
  var written = total;
1499
1472
 
1500
1473
  if (total & 1) {
1501
- stream.writeHex(this.padByte);
1474
+ stream.writeUint8(this.padByte);
1502
1475
  written++;
1503
1476
  }
1504
1477
 
@@ -1507,19 +1480,23 @@
1507
1480
  }], [{
1508
1481
  key: "createByTypeString",
1509
1482
  value: function createByTypeString(type) {
1510
- var vr = null;
1511
- 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") {
1512
- // TODO: determine VR based on context (could be 1 byte pixel data)
1513
- // https://github.com/dgobbi/vtk-dicom/issues/38
1514
- log.error("Invalid vr type " + type + " - using OW");
1515
- vr = new OtherWordString();
1516
- } else if (type == "xs") {
1517
- log.error("Invalid vr type " + type + " - using US");
1518
- vr = new UnsignedShort();
1519
- } else {
1520
- log.error("Invalid vr type " + type + " - using UN");
1521
- vr = new UnknownValue();
1483
+ var vr = VRinstances[type];
1484
+
1485
+ if (vr === undefined) {
1486
+ if (type == "ox") {
1487
+ // TODO: determine VR based on context (could be 1 byte pixel data)
1488
+ // https://github.com/dgobbi/vtk-dicom/issues/38
1489
+ log.error("Invalid vr type " + type + " - using OW");
1490
+ vr = VRinstances["OW"];
1491
+ } else if (type == "xs") {
1492
+ log.error("Invalid vr type " + type + " - using US");
1493
+ vr = VRinstances["US"];
1494
+ } else {
1495
+ log.error("Invalid vr type " + type + " - using UN");
1496
+ vr = VRinstances["UN"];
1497
+ }
1522
1498
  }
1499
+
1523
1500
  return vr;
1524
1501
  }
1525
1502
  }]);
@@ -1527,46 +1504,71 @@
1527
1504
  return ValueRepresentation;
1528
1505
  }();
1529
1506
 
1530
- var StringRepresentation = /*#__PURE__*/function (_ValueRepresentation) {
1531
- _inherits(StringRepresentation, _ValueRepresentation);
1507
+ var AsciiStringRepresentation = /*#__PURE__*/function (_ValueRepresentation) {
1508
+ _inherits(AsciiStringRepresentation, _ValueRepresentation);
1532
1509
 
1533
- var _super = _createSuper(StringRepresentation);
1510
+ var _super = _createSuper(AsciiStringRepresentation);
1534
1511
 
1535
- function StringRepresentation(type) {
1536
- _classCallCheck(this, StringRepresentation);
1512
+ function AsciiStringRepresentation(type) {
1513
+ _classCallCheck(this, AsciiStringRepresentation);
1537
1514
 
1538
1515
  return _super.call(this, type);
1539
1516
  }
1540
1517
 
1541
- _createClass(StringRepresentation, [{
1518
+ _createClass(AsciiStringRepresentation, [{
1542
1519
  key: "readBytes",
1543
1520
  value: function readBytes(stream, length) {
1544
- return stream.readString(length);
1521
+ return stream.readAsciiString(length);
1545
1522
  }
1546
1523
  }, {
1547
1524
  key: "writeBytes",
1548
1525
  value: function writeBytes(stream, value, writeOptions) {
1549
- // TODO will delete
1550
- if (!writeOptions) throw new Error("writeOptions is undefined");
1526
+ var written = _get(_getPrototypeOf(AsciiStringRepresentation.prototype), "write", this).call(this, stream, "AsciiString", value);
1527
+
1528
+ return _get(_getPrototypeOf(AsciiStringRepresentation.prototype), "writeBytes", this).call(this, stream, value, written, writeOptions);
1529
+ }
1530
+ }]);
1531
+
1532
+ return AsciiStringRepresentation;
1533
+ }(ValueRepresentation);
1551
1534
 
1552
- var written = _get(_getPrototypeOf(StringRepresentation.prototype), "write", this).call(this, stream, "String", value);
1535
+ var EncodedStringRepresentation = /*#__PURE__*/function (_ValueRepresentation2) {
1536
+ _inherits(EncodedStringRepresentation, _ValueRepresentation2);
1553
1537
 
1554
- return _get(_getPrototypeOf(StringRepresentation.prototype), "writeBytes", this).call(this, stream, value, written, writeOptions);
1538
+ var _super2 = _createSuper(EncodedStringRepresentation);
1539
+
1540
+ function EncodedStringRepresentation(type) {
1541
+ _classCallCheck(this, EncodedStringRepresentation);
1542
+
1543
+ return _super2.call(this, type);
1544
+ }
1545
+
1546
+ _createClass(EncodedStringRepresentation, [{
1547
+ key: "readBytes",
1548
+ value: function readBytes(stream, length) {
1549
+ return stream.readEncodedString(length);
1550
+ }
1551
+ }, {
1552
+ key: "writeBytes",
1553
+ value: function writeBytes(stream, value, writeOptions) {
1554
+ var written = _get(_getPrototypeOf(EncodedStringRepresentation.prototype), "write", this).call(this, stream, "UTF8String", value);
1555
+
1556
+ return _get(_getPrototypeOf(EncodedStringRepresentation.prototype), "writeBytes", this).call(this, stream, value, written, writeOptions);
1555
1557
  }
1556
1558
  }]);
1557
1559
 
1558
- return StringRepresentation;
1560
+ return EncodedStringRepresentation;
1559
1561
  }(ValueRepresentation);
1560
1562
 
1561
- var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation2) {
1562
- _inherits(BinaryRepresentation, _ValueRepresentation2);
1563
+ var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation3) {
1564
+ _inherits(BinaryRepresentation, _ValueRepresentation3);
1563
1565
 
1564
- var _super2 = _createSuper(BinaryRepresentation);
1566
+ var _super3 = _createSuper(BinaryRepresentation);
1565
1567
 
1566
1568
  function BinaryRepresentation(type) {
1567
1569
  _classCallCheck(this, BinaryRepresentation);
1568
1570
 
1569
- return _super2.call(this, type);
1571
+ return _super3.call(this, type);
1570
1572
  }
1571
1573
 
1572
1574
  _createClass(BinaryRepresentation, [{
@@ -1645,7 +1647,7 @@
1645
1647
  var written = 8 + binaryStream.size + startOffset.length * 4 + 8;
1646
1648
 
1647
1649
  if (written & 1) {
1648
- stream.writeHex(this.padByte);
1650
+ stream.writeUint8(this.padByte);
1649
1651
  written++;
1650
1652
  }
1651
1653
 
@@ -1795,95 +1797,93 @@
1795
1797
  return BinaryRepresentation;
1796
1798
  }(ValueRepresentation);
1797
1799
 
1798
- var ApplicationEntity = /*#__PURE__*/function (_StringRepresentation) {
1799
- _inherits(ApplicationEntity, _StringRepresentation);
1800
+ var ApplicationEntity = /*#__PURE__*/function (_AsciiStringRepresent) {
1801
+ _inherits(ApplicationEntity, _AsciiStringRepresent);
1800
1802
 
1801
- var _super3 = _createSuper(ApplicationEntity);
1803
+ var _super4 = _createSuper(ApplicationEntity);
1802
1804
 
1803
1805
  function ApplicationEntity() {
1804
1806
  var _this;
1805
1807
 
1806
1808
  _classCallCheck(this, ApplicationEntity);
1807
1809
 
1808
- _this = _super3.call(this, "AE");
1810
+ _this = _super4.call(this, "AE");
1809
1811
  _this.maxLength = 16;
1810
- _this.padByte = "20";
1811
- _this.fillWith = "20";
1812
+ _this.padByte = 0x20;
1812
1813
  return _this;
1813
1814
  }
1814
1815
 
1815
1816
  _createClass(ApplicationEntity, [{
1816
1817
  key: "readBytes",
1817
1818
  value: function readBytes(stream, length) {
1818
- return stream.readString(length).trim();
1819
+ return stream.readAsciiString(length).trim();
1819
1820
  }
1820
1821
  }]);
1821
1822
 
1822
1823
  return ApplicationEntity;
1823
- }(StringRepresentation);
1824
+ }(AsciiStringRepresentation);
1824
1825
 
1825
- var CodeString = /*#__PURE__*/function (_StringRepresentation2) {
1826
- _inherits(CodeString, _StringRepresentation2);
1826
+ var CodeString = /*#__PURE__*/function (_AsciiStringRepresent2) {
1827
+ _inherits(CodeString, _AsciiStringRepresent2);
1827
1828
 
1828
- var _super4 = _createSuper(CodeString);
1829
+ var _super5 = _createSuper(CodeString);
1829
1830
 
1830
1831
  function CodeString() {
1831
1832
  var _this2;
1832
1833
 
1833
1834
  _classCallCheck(this, CodeString);
1834
1835
 
1835
- _this2 = _super4.call(this, "CS");
1836
+ _this2 = _super5.call(this, "CS");
1836
1837
  _this2.maxLength = 16;
1837
- _this2.padByte = "20";
1838
+ _this2.padByte = 0x20;
1838
1839
  return _this2;
1839
1840
  }
1840
1841
 
1841
1842
  _createClass(CodeString, [{
1842
1843
  key: "readBytes",
1843
1844
  value: function readBytes(stream, length) {
1844
- //return this.readNullPaddedString(stream, length).trim();
1845
- return stream.readString(length).trim();
1845
+ return stream.readAsciiString(length).trim();
1846
1846
  }
1847
1847
  }]);
1848
1848
 
1849
1849
  return CodeString;
1850
- }(StringRepresentation);
1850
+ }(AsciiStringRepresentation);
1851
1851
 
1852
- var AgeString = /*#__PURE__*/function (_StringRepresentation3) {
1853
- _inherits(AgeString, _StringRepresentation3);
1852
+ var AgeString = /*#__PURE__*/function (_AsciiStringRepresent3) {
1853
+ _inherits(AgeString, _AsciiStringRepresent3);
1854
1854
 
1855
- var _super5 = _createSuper(AgeString);
1855
+ var _super6 = _createSuper(AgeString);
1856
1856
 
1857
1857
  function AgeString() {
1858
1858
  var _this3;
1859
1859
 
1860
1860
  _classCallCheck(this, AgeString);
1861
1861
 
1862
- _this3 = _super5.call(this, "AS");
1862
+ _this3 = _super6.call(this, "AS");
1863
1863
  _this3.maxLength = 4;
1864
- _this3.padByte = "20";
1864
+ _this3.padByte = 0x20;
1865
1865
  _this3.fixed = true;
1866
1866
  _this3.defaultValue = "";
1867
1867
  return _this3;
1868
1868
  }
1869
1869
 
1870
1870
  return _createClass(AgeString);
1871
- }(StringRepresentation);
1871
+ }(AsciiStringRepresentation);
1872
1872
 
1873
- var AttributeTag = /*#__PURE__*/function (_ValueRepresentation3) {
1874
- _inherits(AttributeTag, _ValueRepresentation3);
1873
+ var AttributeTag = /*#__PURE__*/function (_ValueRepresentation4) {
1874
+ _inherits(AttributeTag, _ValueRepresentation4);
1875
1875
 
1876
- var _super6 = _createSuper(AttributeTag);
1876
+ var _super7 = _createSuper(AttributeTag);
1877
1877
 
1878
1878
  function AttributeTag() {
1879
1879
  var _this4;
1880
1880
 
1881
1881
  _classCallCheck(this, AttributeTag);
1882
1882
 
1883
- _this4 = _super6.call(this, "AT");
1883
+ _this4 = _super7.call(this, "AT");
1884
1884
  _this4.maxLength = 4;
1885
1885
  _this4.valueLength = 4;
1886
- _this4.padByte = "00";
1886
+ _this4.padByte = 0;
1887
1887
  _this4.fixed = true;
1888
1888
  return _this4;
1889
1889
  }
@@ -1903,49 +1903,48 @@
1903
1903
  return AttributeTag;
1904
1904
  }(ValueRepresentation);
1905
1905
 
1906
- var DateValue = /*#__PURE__*/function (_StringRepresentation4) {
1907
- _inherits(DateValue, _StringRepresentation4);
1906
+ var DateValue = /*#__PURE__*/function (_AsciiStringRepresent4) {
1907
+ _inherits(DateValue, _AsciiStringRepresent4);
1908
1908
 
1909
- var _super7 = _createSuper(DateValue);
1909
+ var _super8 = _createSuper(DateValue);
1910
1910
 
1911
1911
  function DateValue(value) {
1912
1912
  var _this5;
1913
1913
 
1914
1914
  _classCallCheck(this, DateValue);
1915
1915
 
1916
- _this5 = _super7.call(this, "DA", value);
1916
+ _this5 = _super8.call(this, "DA", value);
1917
1917
  _this5.maxLength = 18;
1918
- _this5.padByte = "20"; //this.fixed = true;
1918
+ _this5.padByte = 0x20; //this.fixed = true;
1919
1919
 
1920
1920
  _this5.defaultValue = "";
1921
1921
  return _this5;
1922
1922
  }
1923
1923
 
1924
1924
  return _createClass(DateValue);
1925
- }(StringRepresentation);
1925
+ }(AsciiStringRepresentation);
1926
1926
 
1927
- var DecimalString = /*#__PURE__*/function (_StringRepresentation5) {
1928
- _inherits(DecimalString, _StringRepresentation5);
1927
+ var DecimalString = /*#__PURE__*/function (_AsciiStringRepresent5) {
1928
+ _inherits(DecimalString, _AsciiStringRepresent5);
1929
1929
 
1930
- var _super8 = _createSuper(DecimalString);
1930
+ var _super9 = _createSuper(DecimalString);
1931
1931
 
1932
1932
  function DecimalString() {
1933
1933
  var _this6;
1934
1934
 
1935
1935
  _classCallCheck(this, DecimalString);
1936
1936
 
1937
- _this6 = _super8.call(this, "DS");
1937
+ _this6 = _super9.call(this, "DS");
1938
1938
  _this6.maxLength = 16;
1939
- _this6.padByte = "20";
1939
+ _this6.padByte = 0x20;
1940
1940
  return _this6;
1941
1941
  }
1942
1942
 
1943
1943
  _createClass(DecimalString, [{
1944
1944
  key: "readBytes",
1945
1945
  value: function readBytes(stream, length) {
1946
- var BACKSLASH = String.fromCharCode(0x5c); //return this.readNullPaddedString(stream, length).trim();
1947
-
1948
- var ds = stream.readString(length);
1946
+ var BACKSLASH = String.fromCharCode(0x5c);
1947
+ var ds = stream.readAsciiString(length);
1949
1948
  ds = ds.replace(/[^0-9.\\\-+e]/gi, "");
1950
1949
 
1951
1950
  if (ds.indexOf(BACKSLASH) !== -1) {
@@ -1988,40 +1987,40 @@
1988
1987
  }]);
1989
1988
 
1990
1989
  return DecimalString;
1991
- }(StringRepresentation);
1990
+ }(AsciiStringRepresentation);
1992
1991
 
1993
- var DateTime = /*#__PURE__*/function (_StringRepresentation6) {
1994
- _inherits(DateTime, _StringRepresentation6);
1992
+ var DateTime = /*#__PURE__*/function (_AsciiStringRepresent6) {
1993
+ _inherits(DateTime, _AsciiStringRepresent6);
1995
1994
 
1996
- var _super9 = _createSuper(DateTime);
1995
+ var _super10 = _createSuper(DateTime);
1997
1996
 
1998
1997
  function DateTime() {
1999
1998
  var _this8;
2000
1999
 
2001
2000
  _classCallCheck(this, DateTime);
2002
2001
 
2003
- _this8 = _super9.call(this, "DT");
2002
+ _this8 = _super10.call(this, "DT");
2004
2003
  _this8.maxLength = 26;
2005
- _this8.padByte = "20";
2004
+ _this8.padByte = 0x20;
2006
2005
  return _this8;
2007
2006
  }
2008
2007
 
2009
2008
  return _createClass(DateTime);
2010
- }(StringRepresentation);
2009
+ }(AsciiStringRepresentation);
2011
2010
 
2012
- var FloatingPointSingle = /*#__PURE__*/function (_ValueRepresentation4) {
2013
- _inherits(FloatingPointSingle, _ValueRepresentation4);
2011
+ var FloatingPointSingle = /*#__PURE__*/function (_ValueRepresentation5) {
2012
+ _inherits(FloatingPointSingle, _ValueRepresentation5);
2014
2013
 
2015
- var _super10 = _createSuper(FloatingPointSingle);
2014
+ var _super11 = _createSuper(FloatingPointSingle);
2016
2015
 
2017
2016
  function FloatingPointSingle() {
2018
2017
  var _this9;
2019
2018
 
2020
2019
  _classCallCheck(this, FloatingPointSingle);
2021
2020
 
2022
- _this9 = _super10.call(this, "FL");
2021
+ _this9 = _super11.call(this, "FL");
2023
2022
  _this9.maxLength = 4;
2024
- _this9.padByte = "00";
2023
+ _this9.padByte = 0;
2025
2024
  _this9.fixed = true;
2026
2025
  _this9.defaultValue = 0.0;
2027
2026
  return _this9;
@@ -2042,19 +2041,19 @@
2042
2041
  return FloatingPointSingle;
2043
2042
  }(ValueRepresentation);
2044
2043
 
2045
- var FloatingPointDouble = /*#__PURE__*/function (_ValueRepresentation5) {
2046
- _inherits(FloatingPointDouble, _ValueRepresentation5);
2044
+ var FloatingPointDouble = /*#__PURE__*/function (_ValueRepresentation6) {
2045
+ _inherits(FloatingPointDouble, _ValueRepresentation6);
2047
2046
 
2048
- var _super11 = _createSuper(FloatingPointDouble);
2047
+ var _super12 = _createSuper(FloatingPointDouble);
2049
2048
 
2050
2049
  function FloatingPointDouble() {
2051
2050
  var _this10;
2052
2051
 
2053
2052
  _classCallCheck(this, FloatingPointDouble);
2054
2053
 
2055
- _this10 = _super11.call(this, "FD");
2054
+ _this10 = _super12.call(this, "FD");
2056
2055
  _this10.maxLength = 8;
2057
- _this10.padByte = "00";
2056
+ _this10.padByte = 0;
2058
2057
  _this10.fixed = true;
2059
2058
  _this10.defaultValue = 0.0;
2060
2059
  return _this10;
@@ -2075,19 +2074,19 @@
2075
2074
  return FloatingPointDouble;
2076
2075
  }(ValueRepresentation);
2077
2076
 
2078
- var IntegerString = /*#__PURE__*/function (_StringRepresentation7) {
2079
- _inherits(IntegerString, _StringRepresentation7);
2077
+ var IntegerString = /*#__PURE__*/function (_AsciiStringRepresent7) {
2078
+ _inherits(IntegerString, _AsciiStringRepresent7);
2080
2079
 
2081
- var _super12 = _createSuper(IntegerString);
2080
+ var _super13 = _createSuper(IntegerString);
2082
2081
 
2083
2082
  function IntegerString() {
2084
2083
  var _this11;
2085
2084
 
2086
2085
  _classCallCheck(this, IntegerString);
2087
2086
 
2088
- _this11 = _super12.call(this, "IS");
2087
+ _this11 = _super13.call(this, "IS");
2089
2088
  _this11.maxLength = 12;
2090
- _this11.padByte = "20";
2089
+ _this11.padByte = 0x20;
2091
2090
  return _this11;
2092
2091
  }
2093
2092
 
@@ -2095,7 +2094,7 @@
2095
2094
  key: "readBytes",
2096
2095
  value: function readBytes(stream, length) {
2097
2096
  var BACKSLASH = String.fromCharCode(0x5c);
2098
- var is = stream.readString(length).trim();
2097
+ var is = stream.readAsciiString(length).trim();
2099
2098
  is = is.replace(/[^0-9.\\\-+e]/gi, "");
2100
2099
 
2101
2100
  if (is.indexOf(BACKSLASH) !== -1) {
@@ -2128,75 +2127,73 @@
2128
2127
  }]);
2129
2128
 
2130
2129
  return IntegerString;
2131
- }(StringRepresentation);
2130
+ }(AsciiStringRepresentation);
2132
2131
 
2133
- var LongString = /*#__PURE__*/function (_StringRepresentation8) {
2134
- _inherits(LongString, _StringRepresentation8);
2132
+ var LongString = /*#__PURE__*/function (_EncodedStringReprese) {
2133
+ _inherits(LongString, _EncodedStringReprese);
2135
2134
 
2136
- var _super13 = _createSuper(LongString);
2135
+ var _super14 = _createSuper(LongString);
2137
2136
 
2138
2137
  function LongString() {
2139
2138
  var _this13;
2140
2139
 
2141
2140
  _classCallCheck(this, LongString);
2142
2141
 
2143
- _this13 = _super13.call(this, "LO");
2142
+ _this13 = _super14.call(this, "LO");
2144
2143
  _this13.maxCharLength = 64;
2145
- _this13.padByte = "20";
2144
+ _this13.padByte = 0x20;
2146
2145
  return _this13;
2147
2146
  }
2148
2147
 
2149
2148
  _createClass(LongString, [{
2150
2149
  key: "readBytes",
2151
2150
  value: function readBytes(stream, length) {
2152
- //return this.readNullPaddedString(stream, length).trim();
2153
- return stream.readString(length).trim();
2151
+ return stream.readEncodedString(length).trim();
2154
2152
  }
2155
2153
  }]);
2156
2154
 
2157
2155
  return LongString;
2158
- }(StringRepresentation);
2156
+ }(EncodedStringRepresentation);
2159
2157
 
2160
- var LongText = /*#__PURE__*/function (_StringRepresentation9) {
2161
- _inherits(LongText, _StringRepresentation9);
2158
+ var LongText = /*#__PURE__*/function (_EncodedStringReprese2) {
2159
+ _inherits(LongText, _EncodedStringReprese2);
2162
2160
 
2163
- var _super14 = _createSuper(LongText);
2161
+ var _super15 = _createSuper(LongText);
2164
2162
 
2165
2163
  function LongText() {
2166
2164
  var _this14;
2167
2165
 
2168
2166
  _classCallCheck(this, LongText);
2169
2167
 
2170
- _this14 = _super14.call(this, "LT");
2168
+ _this14 = _super15.call(this, "LT");
2171
2169
  _this14.maxCharLength = 10240;
2172
- _this14.padByte = "20";
2170
+ _this14.padByte = 0x20;
2173
2171
  return _this14;
2174
2172
  }
2175
2173
 
2176
2174
  _createClass(LongText, [{
2177
2175
  key: "readBytes",
2178
2176
  value: function readBytes(stream, length) {
2179
- //return rtrim(this.readNullPaddedString(stream, length));
2180
- return rtrim(stream.readString(length));
2177
+ return rtrim(stream.readEncodedString(length));
2181
2178
  }
2182
2179
  }]);
2183
2180
 
2184
2181
  return LongText;
2185
- }(StringRepresentation);
2182
+ }(EncodedStringRepresentation);
2186
2183
 
2187
- var PersonName = /*#__PURE__*/function (_StringRepresentation10) {
2188
- _inherits(PersonName, _StringRepresentation10);
2184
+ var PersonName = /*#__PURE__*/function (_EncodedStringReprese3) {
2185
+ _inherits(PersonName, _EncodedStringReprese3);
2189
2186
 
2190
- var _super15 = _createSuper(PersonName);
2187
+ var _super16 = _createSuper(PersonName);
2191
2188
 
2192
2189
  function PersonName() {
2193
2190
  var _this15;
2194
2191
 
2195
2192
  _classCallCheck(this, PersonName);
2196
2193
 
2197
- _this15 = _super15.call(this, "PN");
2194
+ _this15 = _super16.call(this, "PN");
2198
2195
  _this15.maxLength = null;
2199
- _this15.padByte = "20";
2196
+ _this15.padByte = 0x20;
2200
2197
  return _this15;
2201
2198
  }
2202
2199
 
@@ -2231,54 +2228,52 @@
2231
2228
  }, {
2232
2229
  key: "readBytes",
2233
2230
  value: function readBytes(stream, length) {
2234
- //return rtrim(this.readNullPaddedString(stream, length));
2235
- return rtrim(stream.readString(length));
2231
+ return rtrim(stream.readEncodedString(length));
2236
2232
  }
2237
2233
  }]);
2238
2234
 
2239
2235
  return PersonName;
2240
- }(StringRepresentation);
2236
+ }(EncodedStringRepresentation);
2241
2237
 
2242
- var ShortString = /*#__PURE__*/function (_StringRepresentation11) {
2243
- _inherits(ShortString, _StringRepresentation11);
2238
+ var ShortString = /*#__PURE__*/function (_EncodedStringReprese4) {
2239
+ _inherits(ShortString, _EncodedStringReprese4);
2244
2240
 
2245
- var _super16 = _createSuper(ShortString);
2241
+ var _super17 = _createSuper(ShortString);
2246
2242
 
2247
2243
  function ShortString() {
2248
2244
  var _this16;
2249
2245
 
2250
2246
  _classCallCheck(this, ShortString);
2251
2247
 
2252
- _this16 = _super16.call(this, "SH");
2248
+ _this16 = _super17.call(this, "SH");
2253
2249
  _this16.maxCharLength = 16;
2254
- _this16.padByte = "20";
2250
+ _this16.padByte = 0x20;
2255
2251
  return _this16;
2256
2252
  }
2257
2253
 
2258
2254
  _createClass(ShortString, [{
2259
2255
  key: "readBytes",
2260
2256
  value: function readBytes(stream, length) {
2261
- //return this.readNullPaddedString(stream, length).trim();
2262
- return stream.readString(length).trim();
2257
+ return stream.readEncodedString(length).trim();
2263
2258
  }
2264
2259
  }]);
2265
2260
 
2266
2261
  return ShortString;
2267
- }(StringRepresentation);
2262
+ }(EncodedStringRepresentation);
2268
2263
 
2269
- var SignedLong = /*#__PURE__*/function (_ValueRepresentation6) {
2270
- _inherits(SignedLong, _ValueRepresentation6);
2264
+ var SignedLong = /*#__PURE__*/function (_ValueRepresentation7) {
2265
+ _inherits(SignedLong, _ValueRepresentation7);
2271
2266
 
2272
- var _super17 = _createSuper(SignedLong);
2267
+ var _super18 = _createSuper(SignedLong);
2273
2268
 
2274
2269
  function SignedLong() {
2275
2270
  var _this17;
2276
2271
 
2277
2272
  _classCallCheck(this, SignedLong);
2278
2273
 
2279
- _this17 = _super17.call(this, "SL");
2274
+ _this17 = _super18.call(this, "SL");
2280
2275
  _this17.maxLength = 4;
2281
- _this17.padByte = "00";
2276
+ _this17.padByte = 0;
2282
2277
  _this17.fixed = true;
2283
2278
  _this17.defaultValue = 0;
2284
2279
  return _this17;
@@ -2299,19 +2294,19 @@
2299
2294
  return SignedLong;
2300
2295
  }(ValueRepresentation);
2301
2296
 
2302
- var SequenceOfItems = /*#__PURE__*/function (_ValueRepresentation7) {
2303
- _inherits(SequenceOfItems, _ValueRepresentation7);
2297
+ var SequenceOfItems = /*#__PURE__*/function (_ValueRepresentation8) {
2298
+ _inherits(SequenceOfItems, _ValueRepresentation8);
2304
2299
 
2305
- var _super18 = _createSuper(SequenceOfItems);
2300
+ var _super19 = _createSuper(SequenceOfItems);
2306
2301
 
2307
2302
  function SequenceOfItems() {
2308
2303
  var _this18;
2309
2304
 
2310
2305
  _classCallCheck(this, SequenceOfItems);
2311
2306
 
2312
- _this18 = _super18.call(this, "SQ");
2307
+ _this18 = _super19.call(this, "SQ");
2313
2308
  _this18.maxLength = null;
2314
- _this18.padByte = "00";
2309
+ _this18.padByte = 0;
2315
2310
  _this18.noMultiple = true;
2316
2311
  return _this18;
2317
2312
  }
@@ -2455,20 +2450,20 @@
2455
2450
  return SequenceOfItems;
2456
2451
  }(ValueRepresentation);
2457
2452
 
2458
- var SignedShort = /*#__PURE__*/function (_ValueRepresentation8) {
2459
- _inherits(SignedShort, _ValueRepresentation8);
2453
+ var SignedShort = /*#__PURE__*/function (_ValueRepresentation9) {
2454
+ _inherits(SignedShort, _ValueRepresentation9);
2460
2455
 
2461
- var _super19 = _createSuper(SignedShort);
2456
+ var _super20 = _createSuper(SignedShort);
2462
2457
 
2463
2458
  function SignedShort() {
2464
2459
  var _this19;
2465
2460
 
2466
2461
  _classCallCheck(this, SignedShort);
2467
2462
 
2468
- _this19 = _super19.call(this, "SS");
2463
+ _this19 = _super20.call(this, "SS");
2469
2464
  _this19.maxLength = 2;
2470
2465
  _this19.valueLength = 2;
2471
- _this19.padByte = "00";
2466
+ _this19.padByte = 0;
2472
2467
  _this19.fixed = true;
2473
2468
  _this19.defaultValue = 0;
2474
2469
  return _this19;
@@ -2489,126 +2484,124 @@
2489
2484
  return SignedShort;
2490
2485
  }(ValueRepresentation);
2491
2486
 
2492
- var ShortText = /*#__PURE__*/function (_StringRepresentation12) {
2493
- _inherits(ShortText, _StringRepresentation12);
2487
+ var ShortText = /*#__PURE__*/function (_EncodedStringReprese5) {
2488
+ _inherits(ShortText, _EncodedStringReprese5);
2494
2489
 
2495
- var _super20 = _createSuper(ShortText);
2490
+ var _super21 = _createSuper(ShortText);
2496
2491
 
2497
2492
  function ShortText() {
2498
2493
  var _this20;
2499
2494
 
2500
2495
  _classCallCheck(this, ShortText);
2501
2496
 
2502
- _this20 = _super20.call(this, "ST");
2497
+ _this20 = _super21.call(this, "ST");
2503
2498
  _this20.maxCharLength = 1024;
2504
- _this20.padByte = "20";
2499
+ _this20.padByte = 0x20;
2505
2500
  return _this20;
2506
2501
  }
2507
2502
 
2508
2503
  _createClass(ShortText, [{
2509
2504
  key: "readBytes",
2510
2505
  value: function readBytes(stream, length) {
2511
- //return rtrim(this.readNullPaddedString(stream, length));
2512
- return rtrim(stream.readString(length));
2506
+ return rtrim(stream.readEncodedString(length));
2513
2507
  }
2514
2508
  }]);
2515
2509
 
2516
2510
  return ShortText;
2517
- }(StringRepresentation);
2511
+ }(EncodedStringRepresentation);
2518
2512
 
2519
- var TimeValue = /*#__PURE__*/function (_StringRepresentation13) {
2520
- _inherits(TimeValue, _StringRepresentation13);
2513
+ var TimeValue = /*#__PURE__*/function (_AsciiStringRepresent8) {
2514
+ _inherits(TimeValue, _AsciiStringRepresent8);
2521
2515
 
2522
- var _super21 = _createSuper(TimeValue);
2516
+ var _super22 = _createSuper(TimeValue);
2523
2517
 
2524
2518
  function TimeValue() {
2525
2519
  var _this21;
2526
2520
 
2527
2521
  _classCallCheck(this, TimeValue);
2528
2522
 
2529
- _this21 = _super21.call(this, "TM");
2523
+ _this21 = _super22.call(this, "TM");
2530
2524
  _this21.maxLength = 14;
2531
- _this21.padByte = "20";
2525
+ _this21.padByte = 0x20;
2532
2526
  return _this21;
2533
2527
  }
2534
2528
 
2535
2529
  _createClass(TimeValue, [{
2536
2530
  key: "readBytes",
2537
2531
  value: function readBytes(stream, length) {
2538
- return rtrim(stream.readString(length));
2532
+ return rtrim(stream.readAsciiString(length));
2539
2533
  }
2540
2534
  }]);
2541
2535
 
2542
2536
  return TimeValue;
2543
- }(StringRepresentation);
2537
+ }(AsciiStringRepresentation);
2544
2538
 
2545
- var UnlimitedCharacters = /*#__PURE__*/function (_StringRepresentation14) {
2546
- _inherits(UnlimitedCharacters, _StringRepresentation14);
2539
+ var UnlimitedCharacters = /*#__PURE__*/function (_EncodedStringReprese6) {
2540
+ _inherits(UnlimitedCharacters, _EncodedStringReprese6);
2547
2541
 
2548
- var _super22 = _createSuper(UnlimitedCharacters);
2542
+ var _super23 = _createSuper(UnlimitedCharacters);
2549
2543
 
2550
2544
  function UnlimitedCharacters() {
2551
2545
  var _this22;
2552
2546
 
2553
2547
  _classCallCheck(this, UnlimitedCharacters);
2554
2548
 
2555
- _this22 = _super22.call(this, "UC");
2549
+ _this22 = _super23.call(this, "UC");
2556
2550
  _this22.maxLength = null;
2557
2551
  _this22.multi = true;
2558
- _this22.padByte = "20";
2552
+ _this22.padByte = 0x20;
2559
2553
  return _this22;
2560
2554
  }
2561
2555
 
2562
2556
  _createClass(UnlimitedCharacters, [{
2563
2557
  key: "readBytes",
2564
2558
  value: function readBytes(stream, length) {
2565
- return rtrim(stream.readString(length));
2559
+ return rtrim(stream.readEncodedString(length));
2566
2560
  }
2567
2561
  }]);
2568
2562
 
2569
2563
  return UnlimitedCharacters;
2570
- }(StringRepresentation);
2564
+ }(EncodedStringRepresentation);
2571
2565
 
2572
- var UnlimitedText = /*#__PURE__*/function (_StringRepresentation15) {
2573
- _inherits(UnlimitedText, _StringRepresentation15);
2566
+ var UnlimitedText = /*#__PURE__*/function (_EncodedStringReprese7) {
2567
+ _inherits(UnlimitedText, _EncodedStringReprese7);
2574
2568
 
2575
- var _super23 = _createSuper(UnlimitedText);
2569
+ var _super24 = _createSuper(UnlimitedText);
2576
2570
 
2577
2571
  function UnlimitedText() {
2578
2572
  var _this23;
2579
2573
 
2580
2574
  _classCallCheck(this, UnlimitedText);
2581
2575
 
2582
- _this23 = _super23.call(this, "UT");
2576
+ _this23 = _super24.call(this, "UT");
2583
2577
  _this23.maxLength = null;
2584
- _this23.padByte = "20";
2578
+ _this23.padByte = 0x20;
2585
2579
  return _this23;
2586
2580
  }
2587
2581
 
2588
2582
  _createClass(UnlimitedText, [{
2589
2583
  key: "readBytes",
2590
2584
  value: function readBytes(stream, length) {
2591
- //return this.readNullPaddedString(stream, length);
2592
- return rtrim(stream.readString(length));
2585
+ return rtrim(stream.readEncodedString(length));
2593
2586
  }
2594
2587
  }]);
2595
2588
 
2596
2589
  return UnlimitedText;
2597
- }(StringRepresentation);
2590
+ }(EncodedStringRepresentation);
2598
2591
 
2599
- var UnsignedShort = /*#__PURE__*/function (_ValueRepresentation9) {
2600
- _inherits(UnsignedShort, _ValueRepresentation9);
2592
+ var UnsignedShort = /*#__PURE__*/function (_ValueRepresentation10) {
2593
+ _inherits(UnsignedShort, _ValueRepresentation10);
2601
2594
 
2602
- var _super24 = _createSuper(UnsignedShort);
2595
+ var _super25 = _createSuper(UnsignedShort);
2603
2596
 
2604
2597
  function UnsignedShort() {
2605
2598
  var _this24;
2606
2599
 
2607
2600
  _classCallCheck(this, UnsignedShort);
2608
2601
 
2609
- _this24 = _super24.call(this, "US");
2602
+ _this24 = _super25.call(this, "US");
2610
2603
  _this24.maxLength = 2;
2611
- _this24.padByte = "00";
2604
+ _this24.padByte = 0;
2612
2605
  _this24.fixed = true;
2613
2606
  _this24.defaultValue = 0;
2614
2607
  return _this24;
@@ -2629,19 +2622,19 @@
2629
2622
  return UnsignedShort;
2630
2623
  }(ValueRepresentation);
2631
2624
 
2632
- var UnsignedLong = /*#__PURE__*/function (_ValueRepresentation10) {
2633
- _inherits(UnsignedLong, _ValueRepresentation10);
2625
+ var UnsignedLong = /*#__PURE__*/function (_ValueRepresentation11) {
2626
+ _inherits(UnsignedLong, _ValueRepresentation11);
2634
2627
 
2635
- var _super25 = _createSuper(UnsignedLong);
2628
+ var _super26 = _createSuper(UnsignedLong);
2636
2629
 
2637
2630
  function UnsignedLong() {
2638
2631
  var _this25;
2639
2632
 
2640
2633
  _classCallCheck(this, UnsignedLong);
2641
2634
 
2642
- _this25 = _super25.call(this, "UL");
2635
+ _this25 = _super26.call(this, "UL");
2643
2636
  _this25.maxLength = 4;
2644
- _this25.padByte = "00";
2637
+ _this25.padByte = 0;
2645
2638
  _this25.fixed = true;
2646
2639
  _this25.defaultValue = 0;
2647
2640
  return _this25;
@@ -2662,19 +2655,19 @@
2662
2655
  return UnsignedLong;
2663
2656
  }(ValueRepresentation);
2664
2657
 
2665
- var UniqueIdentifier = /*#__PURE__*/function (_StringRepresentation16) {
2666
- _inherits(UniqueIdentifier, _StringRepresentation16);
2658
+ var UniqueIdentifier = /*#__PURE__*/function (_AsciiStringRepresent9) {
2659
+ _inherits(UniqueIdentifier, _AsciiStringRepresent9);
2667
2660
 
2668
- var _super26 = _createSuper(UniqueIdentifier);
2661
+ var _super27 = _createSuper(UniqueIdentifier);
2669
2662
 
2670
2663
  function UniqueIdentifier() {
2671
2664
  var _this26;
2672
2665
 
2673
2666
  _classCallCheck(this, UniqueIdentifier);
2674
2667
 
2675
- _this26 = _super26.call(this, "UI");
2668
+ _this26 = _super27.call(this, "UI");
2676
2669
  _this26.maxLength = 64;
2677
- _this26.padByte = "00";
2670
+ _this26.padByte = 0;
2678
2671
  return _this26;
2679
2672
  }
2680
2673
 
@@ -2702,47 +2695,47 @@
2702
2695
  }]);
2703
2696
 
2704
2697
  return UniqueIdentifier;
2705
- }(StringRepresentation);
2698
+ }(AsciiStringRepresentation);
2706
2699
 
2707
- var UniversalResource = /*#__PURE__*/function (_StringRepresentation17) {
2708
- _inherits(UniversalResource, _StringRepresentation17);
2700
+ var UniversalResource = /*#__PURE__*/function (_AsciiStringRepresent10) {
2701
+ _inherits(UniversalResource, _AsciiStringRepresent10);
2709
2702
 
2710
- var _super27 = _createSuper(UniversalResource);
2703
+ var _super28 = _createSuper(UniversalResource);
2711
2704
 
2712
2705
  function UniversalResource() {
2713
2706
  var _this27;
2714
2707
 
2715
2708
  _classCallCheck(this, UniversalResource);
2716
2709
 
2717
- _this27 = _super27.call(this, "UR");
2710
+ _this27 = _super28.call(this, "UR");
2718
2711
  _this27.maxLength = null;
2719
- _this27.padByte = "20";
2712
+ _this27.padByte = 0x20;
2720
2713
  return _this27;
2721
2714
  }
2722
2715
 
2723
2716
  _createClass(UniversalResource, [{
2724
2717
  key: "readBytes",
2725
2718
  value: function readBytes(stream, length) {
2726
- return stream.readString(length);
2719
+ return stream.readAsciiString(length);
2727
2720
  }
2728
2721
  }]);
2729
2722
 
2730
2723
  return UniversalResource;
2731
- }(StringRepresentation);
2724
+ }(AsciiStringRepresentation);
2732
2725
 
2733
2726
  var UnknownValue = /*#__PURE__*/function (_BinaryRepresentation) {
2734
2727
  _inherits(UnknownValue, _BinaryRepresentation);
2735
2728
 
2736
- var _super28 = _createSuper(UnknownValue);
2729
+ var _super29 = _createSuper(UnknownValue);
2737
2730
 
2738
2731
  function UnknownValue() {
2739
2732
  var _this28;
2740
2733
 
2741
2734
  _classCallCheck(this, UnknownValue);
2742
2735
 
2743
- _this28 = _super28.call(this, "UN");
2736
+ _this28 = _super29.call(this, "UN");
2744
2737
  _this28.maxLength = null;
2745
- _this28.padByte = "00";
2738
+ _this28.padByte = 0;
2746
2739
  _this28.noMultiple = true;
2747
2740
  return _this28;
2748
2741
  }
@@ -2753,16 +2746,16 @@
2753
2746
  var OtherWordString = /*#__PURE__*/function (_BinaryRepresentation2) {
2754
2747
  _inherits(OtherWordString, _BinaryRepresentation2);
2755
2748
 
2756
- var _super29 = _createSuper(OtherWordString);
2749
+ var _super30 = _createSuper(OtherWordString);
2757
2750
 
2758
2751
  function OtherWordString() {
2759
2752
  var _this29;
2760
2753
 
2761
2754
  _classCallCheck(this, OtherWordString);
2762
2755
 
2763
- _this29 = _super29.call(this, "OW");
2756
+ _this29 = _super30.call(this, "OW");
2764
2757
  _this29.maxLength = null;
2765
- _this29.padByte = "00";
2758
+ _this29.padByte = 0;
2766
2759
  _this29.noMultiple = true;
2767
2760
  return _this29;
2768
2761
  }
@@ -2773,16 +2766,16 @@
2773
2766
  var OtherByteString = /*#__PURE__*/function (_BinaryRepresentation3) {
2774
2767
  _inherits(OtherByteString, _BinaryRepresentation3);
2775
2768
 
2776
- var _super30 = _createSuper(OtherByteString);
2769
+ var _super31 = _createSuper(OtherByteString);
2777
2770
 
2778
2771
  function OtherByteString() {
2779
2772
  var _this30;
2780
2773
 
2781
2774
  _classCallCheck(this, OtherByteString);
2782
2775
 
2783
- _this30 = _super30.call(this, "OB");
2776
+ _this30 = _super31.call(this, "OB");
2784
2777
  _this30.maxLength = null;
2785
- _this30.padByte = "00";
2778
+ _this30.padByte = 0;
2786
2779
  _this30.noMultiple = true;
2787
2780
  return _this30;
2788
2781
  }
@@ -2793,16 +2786,16 @@
2793
2786
  var OtherDoubleString = /*#__PURE__*/function (_BinaryRepresentation4) {
2794
2787
  _inherits(OtherDoubleString, _BinaryRepresentation4);
2795
2788
 
2796
- var _super31 = _createSuper(OtherDoubleString);
2789
+ var _super32 = _createSuper(OtherDoubleString);
2797
2790
 
2798
2791
  function OtherDoubleString() {
2799
2792
  var _this31;
2800
2793
 
2801
2794
  _classCallCheck(this, OtherDoubleString);
2802
2795
 
2803
- _this31 = _super31.call(this, "OD");
2796
+ _this31 = _super32.call(this, "OD");
2804
2797
  _this31.maxLength = null;
2805
- _this31.padByte = "00";
2798
+ _this31.padByte = 0;
2806
2799
  _this31.noMultiple = true;
2807
2800
  return _this31;
2808
2801
  }
@@ -2813,22 +2806,56 @@
2813
2806
  var OtherFloatString = /*#__PURE__*/function (_BinaryRepresentation5) {
2814
2807
  _inherits(OtherFloatString, _BinaryRepresentation5);
2815
2808
 
2816
- var _super32 = _createSuper(OtherFloatString);
2809
+ var _super33 = _createSuper(OtherFloatString);
2817
2810
 
2818
2811
  function OtherFloatString() {
2819
2812
  var _this32;
2820
2813
 
2821
2814
  _classCallCheck(this, OtherFloatString);
2822
2815
 
2823
- _this32 = _super32.call(this, "OF");
2816
+ _this32 = _super33.call(this, "OF");
2824
2817
  _this32.maxLength = null;
2825
- _this32.padByte = "00";
2818
+ _this32.padByte = 0;
2826
2819
  _this32.noMultiple = true;
2827
2820
  return _this32;
2828
2821
  }
2829
2822
 
2830
2823
  return _createClass(OtherFloatString);
2831
- }(BinaryRepresentation);
2824
+ }(BinaryRepresentation); // these VR instances are precreate and are reused for each requested vr/tag
2825
+
2826
+
2827
+ var VRinstances = {
2828
+ AE: new ApplicationEntity(),
2829
+ AS: new AgeString(),
2830
+ AT: new AttributeTag(),
2831
+ CS: new CodeString(),
2832
+ DA: new DateValue(),
2833
+ DS: new DecimalString(),
2834
+ DT: new DateTime(),
2835
+ FL: new FloatingPointSingle(),
2836
+ FD: new FloatingPointDouble(),
2837
+ IS: new IntegerString(),
2838
+ LO: new LongString(),
2839
+ LT: new LongText(),
2840
+ OB: new OtherByteString(),
2841
+ OD: new OtherDoubleString(),
2842
+ OF: new OtherFloatString(),
2843
+ OW: new OtherWordString(),
2844
+ PN: new PersonName(),
2845
+ SH: new ShortString(),
2846
+ SL: new SignedLong(),
2847
+ SQ: new SequenceOfItems(),
2848
+ SS: new SignedShort(),
2849
+ ST: new ShortText(),
2850
+ TM: new TimeValue(),
2851
+ UC: new UnlimitedCharacters(),
2852
+ UI: new UniqueIdentifier(),
2853
+ UL: new UnsignedLong(),
2854
+ UN: new UnknownValue(),
2855
+ UR: new UniversalResource(),
2856
+ US: new UnsignedShort(),
2857
+ UT: new UnlimitedText()
2858
+ };
2832
2859
 
2833
2860
  var IMPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2";
2834
2861
  var EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1";
@@ -2917,12 +2944,12 @@
2917
2944
  written += 4;
2918
2945
  } else {
2919
2946
  if (vr.isExplicit()) {
2920
- stream.writeString(vr.type);
2921
- stream.writeHex("0000");
2947
+ stream.writeAsciiString(vr.type);
2948
+ stream.writeUint16(0);
2922
2949
  stream.writeUint32(valueLength);
2923
2950
  written += 8;
2924
2951
  } else {
2925
- stream.writeString(vr.type);
2952
+ stream.writeAsciiString(vr.type);
2926
2953
  stream.writeUint16(valueLength);
2927
2954
  written += 4;
2928
2955
  }
@@ -3394,6 +3421,10 @@
3394
3421
  var EXPLICIT_LITTLE_ENDIAN$1 = "1.2.840.10008.1.2.1";
3395
3422
  var EXPLICIT_BIG_ENDIAN = "1.2.840.10008.1.2.2";
3396
3423
  var singleVRs$1 = ["SQ", "OF", "OW", "OB", "UN", "LT"];
3424
+ var encodingMapping = {
3425
+ "iso-ir-192": "utf-8",
3426
+ "": "latin1"
3427
+ };
3397
3428
  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"];
3398
3429
 
3399
3430
  var DicomMessage = /*#__PURE__*/function () {
@@ -3441,6 +3472,30 @@
3441
3472
  var readInfo = DicomMessage._readTag(bufferStream, syntax, options);
3442
3473
 
3443
3474
  var cleanTagString = readInfo.tag.toCleanString();
3475
+
3476
+ if (cleanTagString === "00080005") {
3477
+ if (readInfo.values.length > 0) {
3478
+ var coding = readInfo.values[0];
3479
+ coding = coding.replaceAll("_", "-").replaceAll(" ", "-").toLowerCase();
3480
+
3481
+ if (coding in encodingMapping) {
3482
+ coding = encodingMapping[coding];
3483
+ }
3484
+
3485
+ try {
3486
+ bufferStream.setDecoder(new TextDecoder(coding));
3487
+ } catch (error) {
3488
+ console.warn(error);
3489
+ }
3490
+ }
3491
+
3492
+ if (readInfo.values.length > 1) {
3493
+ console.warn("multiple encodings not supported, using first encoding!", readInfo.values);
3494
+ }
3495
+
3496
+ readInfo.values = ["ISO_IR 192"]; // change SpecificCharacterSet to UTF-8
3497
+ }
3498
+
3444
3499
  dict[cleanTagString] = {
3445
3500
  vr: readInfo.vr.type,
3446
3501
  Value: readInfo.values
@@ -3491,7 +3546,7 @@
3491
3546
  stream.reset();
3492
3547
  stream.increment(128);
3493
3548
 
3494
- if (stream.readString(4) !== "DICM") {
3549
+ if (stream.readAsciiString(4) !== "DICM") {
3495
3550
  throw new Error("Invalid a dicom file");
3496
3551
  }
3497
3552
 
@@ -3585,7 +3640,7 @@
3585
3640
 
3586
3641
  vr = ValueRepresentation.createByTypeString(vrType);
3587
3642
  } else {
3588
- vrType = stream.readString(2);
3643
+ vrType = stream.readVR();
3589
3644
  vr = ValueRepresentation.createByTypeString(vrType);
3590
3645
 
3591
3646
  if (vr.isExplicit()) {
@@ -3670,8 +3725,8 @@
3670
3725
  };
3671
3726
  var metaSyntax = EXPLICIT_LITTLE_ENDIAN$2;
3672
3727
  var fileStream = new WriteBufferStream(4096, true);
3673
- fileStream.writeHex("00".repeat(128));
3674
- fileStream.writeString("DICM");
3728
+ fileStream.writeUint8Repeat(0, 128);
3729
+ fileStream.writeAsciiString("DICM");
3675
3730
  var metaStream = new WriteBufferStream(1024);
3676
3731
 
3677
3732
  if (!this.meta["00020010"]) {