dcmjs 0.24.1 → 0.24.4

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",
@@ -1176,7 +1168,8 @@ var ReadBufferStream = /*#__PURE__*/function (_BufferStream) {
1176
1168
 
1177
1169
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
1178
1170
  start: null,
1179
- stop: null
1171
+ stop: null,
1172
+ noCopy: false
1180
1173
  };
1181
1174
 
1182
1175
  _classCallCheck(this, ReadBufferStream);
@@ -1184,28 +1177,31 @@ var ReadBufferStream = /*#__PURE__*/function (_BufferStream) {
1184
1177
  _this = _super.call(this, buffer, littleEndian);
1185
1178
  _this.offset = options.start || 0;
1186
1179
  _this.size = options.stop || _this.buffer.byteLength;
1180
+ _this.noCopy = options.noCopy;
1187
1181
  _this.startOffset = _this.offset;
1188
1182
  _this.endOffset = _this.size;
1183
+ _this.decoder = new TextDecoder("latin1");
1189
1184
  return _this;
1190
1185
  }
1191
1186
 
1192
1187
  _createClass(ReadBufferStream, [{
1193
- key: "readString",
1194
- value: function readString(length) {
1195
- var chars = [];
1196
- var start = this.offset;
1197
- var end = this.offset + length;
1198
-
1199
- if (end >= this.endOffset) {
1200
- end = this.endOffset;
1188
+ key: "setDecoder",
1189
+ value: function setDecoder(decoder) {
1190
+ this.decoder = decoder;
1191
+ }
1192
+ }, {
1193
+ key: "getBuffer",
1194
+ value: function getBuffer(start, end) {
1195
+ if (this.noCopy) {
1196
+ return new Uint8Array(this.buffer, start, end - start);
1201
1197
  }
1202
1198
 
1203
- for (var i = start; i < end; ++i) {
1204
- chars.push(String.fromCharCode(this.view.getUint8(i)));
1205
- this.increment(1);
1199
+ if (!start && !end) {
1200
+ start = 0;
1201
+ end = this.size;
1206
1202
  }
1207
1203
 
1208
- return chars.join("");
1204
+ return this.buffer.slice(start, end);
1209
1205
  }
1210
1206
  }, {
1211
1207
  key: "reset",
@@ -1228,6 +1224,11 @@ var ReadBufferStream = /*#__PURE__*/function (_BufferStream) {
1228
1224
  value: function writeUint8(value) {
1229
1225
  throw new Error(value, "writeUint8 not implemented");
1230
1226
  }
1227
+ }, {
1228
+ key: "writeUint8Repeat",
1229
+ value: function writeUint8Repeat(value, count) {
1230
+ throw new Error(value, "writeUint8Repeat not implemented");
1231
+ }
1231
1232
  }, {
1232
1233
  key: "writeInt8",
1233
1234
  value: function writeInt8(value) {
@@ -1269,14 +1270,14 @@ var ReadBufferStream = /*#__PURE__*/function (_BufferStream) {
1269
1270
  throw new Error(value, "writeDouble not implemented");
1270
1271
  }
1271
1272
  }, {
1272
- key: "writeString",
1273
- value: function writeString(value) {
1274
- throw new Error(value, "writeString not implemented");
1273
+ key: "writeAsciiString",
1274
+ value: function writeAsciiString(value) {
1275
+ throw new Error(value, "writeAsciiString not implemented");
1275
1276
  }
1276
1277
  }, {
1277
- key: "writeHex",
1278
- value: function writeHex(value) {
1279
- throw new Error(value, "writeHex not implemented");
1278
+ key: "writeUTF8String",
1279
+ value: function writeUTF8String(value) {
1280
+ throw new Error(value, "writeUTF8String not implemented");
1280
1281
  }
1281
1282
  }, {
1282
1283
  key: "checkSize",
@@ -1311,25 +1312,10 @@ var WriteBufferStream = /*#__PURE__*/function (_BufferStream2) {
1311
1312
  return _createClass(WriteBufferStream);
1312
1313
  }(BufferStream);
1313
1314
 
1314
- function paddingLeft(paddingValue, string) {
1315
- return String(paddingValue + string).slice(-paddingValue.length);
1316
- }
1317
-
1318
1315
  function rtrim(str) {
1319
1316
  return str.replace(/\s*$/g, "");
1320
1317
  }
1321
1318
 
1322
- function tagFromNumbers(group, element) {
1323
- return new Tag((group << 16 | element) >>> 0);
1324
- }
1325
-
1326
- function readTag(stream) {
1327
- var group = stream.readUint16(),
1328
- element = stream.readUint16();
1329
- var tag = tagFromNumbers(group, element);
1330
- return tag;
1331
- }
1332
-
1333
1319
  function toWindows(inputArray, size) {
1334
1320
  return Array.from({
1335
1321
  length: inputArray.length - (size - 1)
@@ -1350,22 +1336,25 @@ var ValueRepresentation = /*#__PURE__*/function () {
1350
1336
 
1351
1337
  this.type = type;
1352
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;
1353
1342
  }
1354
1343
 
1355
1344
  _createClass(ValueRepresentation, [{
1356
1345
  key: "isBinary",
1357
1346
  value: function isBinary() {
1358
- return binaryVRs.indexOf(this.type) != -1;
1347
+ return this._isBinary;
1359
1348
  }
1360
1349
  }, {
1361
1350
  key: "allowMultiple",
1362
1351
  value: function allowMultiple() {
1363
- return !this.isBinary() && singleVRs.indexOf(this.type) == -1;
1352
+ return this._allowMultiple;
1364
1353
  }
1365
1354
  }, {
1366
1355
  key: "isExplicit",
1367
1356
  value: function isExplicit() {
1368
- return explicitVRs.indexOf(this.type) != -1;
1357
+ return this._isExplicit;
1369
1358
  }
1370
1359
  }, {
1371
1360
  key: "read",
@@ -1380,34 +1369,19 @@ var ValueRepresentation = /*#__PURE__*/function () {
1380
1369
  }, {
1381
1370
  key: "readBytes",
1382
1371
  value: function readBytes(stream, length) {
1383
- return stream.readString(length);
1372
+ return stream.readAsciiString(length);
1384
1373
  }
1385
1374
  }, {
1386
1375
  key: "readNullPaddedString",
1387
1376
  value: function readNullPaddedString(stream, length) {
1388
1377
  if (!length) return "";
1389
- var str = stream.readString(length - 1);
1390
-
1391
- if (stream.readUint8() != 0) {
1392
- stream.increment(-1);
1393
- str += stream.readString(1);
1394
- }
1395
1378
 
1396
- return str;
1397
- }
1398
- }, {
1399
- key: "writeFilledString",
1400
- value: function writeFilledString(stream, value, length) {
1401
- if (length < this.maxLength && length >= 0) {
1402
- var written = 0;
1403
- if (length > 0) written += stream.writeString(value);
1404
- var zeroLength = this.maxLength - length;
1405
- written += stream.writeHex(this.fillWith.repeat(zeroLength));
1406
- return written;
1407
- } else if (length == this.maxLength) {
1408
- return stream.writeString(value);
1379
+ if (stream.peekUint8(length - 1) !== 0) {
1380
+ return stream.readAsciiString(length);
1409
1381
  } else {
1410
- throw "Length mismatch";
1382
+ var val = stream.readAsciiString(length - 1);
1383
+ stream.increment(1);
1384
+ return val;
1411
1385
  }
1412
1386
  }
1413
1387
  }, {
@@ -1416,7 +1390,7 @@ var ValueRepresentation = /*#__PURE__*/function () {
1416
1390
  var args = Array.from(arguments);
1417
1391
 
1418
1392
  if (args[2] === null || args[2] === "" || args[2] === undefined) {
1419
- return [stream.writeString("")];
1393
+ return [stream.writeAsciiString("")];
1420
1394
  } else {
1421
1395
  var written = [],
1422
1396
  valueArgs = args.slice(2),
@@ -1429,7 +1403,7 @@ var ValueRepresentation = /*#__PURE__*/function () {
1429
1403
  var self = this;
1430
1404
  valueArgs[0].forEach(function (v, k) {
1431
1405
  if (self.allowMultiple() && k > 0) {
1432
- stream.writeHex("5C"); //byteCount++;
1406
+ stream.writeUint8(0x5c);
1433
1407
  }
1434
1408
 
1435
1409
  var singularArgs = [v].concat(valueArgs.slice(1));
@@ -1491,7 +1465,7 @@ var ValueRepresentation = /*#__PURE__*/function () {
1491
1465
  var written = total;
1492
1466
 
1493
1467
  if (total & 1) {
1494
- stream.writeHex(this.padByte);
1468
+ stream.writeUint8(this.padByte);
1495
1469
  written++;
1496
1470
  }
1497
1471
 
@@ -1500,19 +1474,23 @@ var ValueRepresentation = /*#__PURE__*/function () {
1500
1474
  }], [{
1501
1475
  key: "createByTypeString",
1502
1476
  value: function createByTypeString(type) {
1503
- var vr = null;
1504
- 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") {
1505
- // TODO: determine VR based on context (could be 1 byte pixel data)
1506
- // https://github.com/dgobbi/vtk-dicom/issues/38
1507
- log.error("Invalid vr type " + type + " - using OW");
1508
- vr = new OtherWordString();
1509
- } else if (type == "xs") {
1510
- log.error("Invalid vr type " + type + " - using US");
1511
- vr = new UnsignedShort();
1512
- } else {
1513
- log.error("Invalid vr type " + type + " - using UN");
1514
- 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
+ }
1515
1492
  }
1493
+
1516
1494
  return vr;
1517
1495
  }
1518
1496
  }]);
@@ -1520,46 +1498,71 @@ var ValueRepresentation = /*#__PURE__*/function () {
1520
1498
  return ValueRepresentation;
1521
1499
  }();
1522
1500
 
1523
- var StringRepresentation = /*#__PURE__*/function (_ValueRepresentation) {
1524
- _inherits(StringRepresentation, _ValueRepresentation);
1501
+ var AsciiStringRepresentation = /*#__PURE__*/function (_ValueRepresentation) {
1502
+ _inherits(AsciiStringRepresentation, _ValueRepresentation);
1525
1503
 
1526
- var _super = _createSuper(StringRepresentation);
1504
+ var _super = _createSuper(AsciiStringRepresentation);
1527
1505
 
1528
- function StringRepresentation(type) {
1529
- _classCallCheck(this, StringRepresentation);
1506
+ function AsciiStringRepresentation(type) {
1507
+ _classCallCheck(this, AsciiStringRepresentation);
1530
1508
 
1531
1509
  return _super.call(this, type);
1532
1510
  }
1533
1511
 
1534
- _createClass(StringRepresentation, [{
1512
+ _createClass(AsciiStringRepresentation, [{
1535
1513
  key: "readBytes",
1536
1514
  value: function readBytes(stream, length) {
1537
- return stream.readString(length);
1515
+ return stream.readAsciiString(length);
1538
1516
  }
1539
1517
  }, {
1540
1518
  key: "writeBytes",
1541
1519
  value: function writeBytes(stream, value, writeOptions) {
1542
- // TODO will delete
1543
- 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);
1544
1528
 
1545
- var written = _get(_getPrototypeOf(StringRepresentation.prototype), "write", this).call(this, stream, "String", value);
1529
+ var EncodedStringRepresentation = /*#__PURE__*/function (_ValueRepresentation2) {
1530
+ _inherits(EncodedStringRepresentation, _ValueRepresentation2);
1546
1531
 
1547
- 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);
1548
1551
  }
1549
1552
  }]);
1550
1553
 
1551
- return StringRepresentation;
1554
+ return EncodedStringRepresentation;
1552
1555
  }(ValueRepresentation);
1553
1556
 
1554
- var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation2) {
1555
- _inherits(BinaryRepresentation, _ValueRepresentation2);
1557
+ var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation3) {
1558
+ _inherits(BinaryRepresentation, _ValueRepresentation3);
1556
1559
 
1557
- var _super2 = _createSuper(BinaryRepresentation);
1560
+ var _super3 = _createSuper(BinaryRepresentation);
1558
1561
 
1559
1562
  function BinaryRepresentation(type) {
1560
1563
  _classCallCheck(this, BinaryRepresentation);
1561
1564
 
1562
- return _super2.call(this, type);
1565
+ return _super3.call(this, type);
1563
1566
  }
1564
1567
 
1565
1568
  _createClass(BinaryRepresentation, [{
@@ -1638,7 +1641,7 @@ var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation2) {
1638
1641
  var written = 8 + binaryStream.size + startOffset.length * 4 + 8;
1639
1642
 
1640
1643
  if (written & 1) {
1641
- stream.writeHex(this.padByte);
1644
+ stream.writeUint8(this.padByte);
1642
1645
  written++;
1643
1646
  }
1644
1647
 
@@ -1716,7 +1719,8 @@ var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation2) {
1716
1719
 
1717
1720
  var rangeStream = new ReadBufferStream(stream.buffer, stream.isLittleEndian, {
1718
1721
  start: start,
1719
- stop: stop
1722
+ stop: stop,
1723
+ noCopy: stream.noCopy
1720
1724
  });
1721
1725
  var frameSize = 0;
1722
1726
 
@@ -1736,16 +1740,21 @@ var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation2) {
1736
1740
 
1737
1741
  if (fragments.length === 1) {
1738
1742
  return fragments[0];
1739
- } // Allocate a final ArrayBuffer and concat all buffers into it
1740
-
1743
+ }
1741
1744
 
1742
- var mergedFrame = new ArrayBuffer(frameSize);
1743
- var u8Data = new Uint8Array(mergedFrame);
1744
- fragments.reduce(function (offset, buffer) {
1745
- u8Data.set(buffer, offset);
1746
- return offset + buffer.byteLength;
1747
- }, 0);
1748
- return mergedFrame;
1745
+ if (rangeStream.noCopy) {
1746
+ // return the fragments for downstream application to process
1747
+ return fragments;
1748
+ } else {
1749
+ // Allocate a final ArrayBuffer and concat all buffers into it
1750
+ var mergedFrame = new ArrayBuffer(frameSize);
1751
+ var u8Data = new Uint8Array(mergedFrame);
1752
+ fragments.reduce(function (offset, buffer) {
1753
+ u8Data.set(new Uint8Array(buffer), offset);
1754
+ return offset + buffer.byteLength;
1755
+ }, 0);
1756
+ return mergedFrame;
1757
+ }
1749
1758
  });
1750
1759
  } // If no offset table, loop through remainder of stream looking for termination tag
1751
1760
  else {
@@ -1782,95 +1791,93 @@ var BinaryRepresentation = /*#__PURE__*/function (_ValueRepresentation2) {
1782
1791
  return BinaryRepresentation;
1783
1792
  }(ValueRepresentation);
1784
1793
 
1785
- var ApplicationEntity = /*#__PURE__*/function (_StringRepresentation) {
1786
- _inherits(ApplicationEntity, _StringRepresentation);
1794
+ var ApplicationEntity = /*#__PURE__*/function (_AsciiStringRepresent) {
1795
+ _inherits(ApplicationEntity, _AsciiStringRepresent);
1787
1796
 
1788
- var _super3 = _createSuper(ApplicationEntity);
1797
+ var _super4 = _createSuper(ApplicationEntity);
1789
1798
 
1790
1799
  function ApplicationEntity() {
1791
1800
  var _this;
1792
1801
 
1793
1802
  _classCallCheck(this, ApplicationEntity);
1794
1803
 
1795
- _this = _super3.call(this, "AE");
1804
+ _this = _super4.call(this, "AE");
1796
1805
  _this.maxLength = 16;
1797
- _this.padByte = "20";
1798
- _this.fillWith = "20";
1806
+ _this.padByte = 0x20;
1799
1807
  return _this;
1800
1808
  }
1801
1809
 
1802
1810
  _createClass(ApplicationEntity, [{
1803
1811
  key: "readBytes",
1804
1812
  value: function readBytes(stream, length) {
1805
- return stream.readString(length).trim();
1813
+ return stream.readAsciiString(length).trim();
1806
1814
  }
1807
1815
  }]);
1808
1816
 
1809
1817
  return ApplicationEntity;
1810
- }(StringRepresentation);
1818
+ }(AsciiStringRepresentation);
1811
1819
 
1812
- var CodeString = /*#__PURE__*/function (_StringRepresentation2) {
1813
- _inherits(CodeString, _StringRepresentation2);
1820
+ var CodeString = /*#__PURE__*/function (_AsciiStringRepresent2) {
1821
+ _inherits(CodeString, _AsciiStringRepresent2);
1814
1822
 
1815
- var _super4 = _createSuper(CodeString);
1823
+ var _super5 = _createSuper(CodeString);
1816
1824
 
1817
1825
  function CodeString() {
1818
1826
  var _this2;
1819
1827
 
1820
1828
  _classCallCheck(this, CodeString);
1821
1829
 
1822
- _this2 = _super4.call(this, "CS");
1830
+ _this2 = _super5.call(this, "CS");
1823
1831
  _this2.maxLength = 16;
1824
- _this2.padByte = "20";
1832
+ _this2.padByte = 0x20;
1825
1833
  return _this2;
1826
1834
  }
1827
1835
 
1828
1836
  _createClass(CodeString, [{
1829
1837
  key: "readBytes",
1830
1838
  value: function readBytes(stream, length) {
1831
- //return this.readNullPaddedString(stream, length).trim();
1832
- return stream.readString(length).trim();
1839
+ return stream.readAsciiString(length).trim();
1833
1840
  }
1834
1841
  }]);
1835
1842
 
1836
1843
  return CodeString;
1837
- }(StringRepresentation);
1844
+ }(AsciiStringRepresentation);
1838
1845
 
1839
- var AgeString = /*#__PURE__*/function (_StringRepresentation3) {
1840
- _inherits(AgeString, _StringRepresentation3);
1846
+ var AgeString = /*#__PURE__*/function (_AsciiStringRepresent3) {
1847
+ _inherits(AgeString, _AsciiStringRepresent3);
1841
1848
 
1842
- var _super5 = _createSuper(AgeString);
1849
+ var _super6 = _createSuper(AgeString);
1843
1850
 
1844
1851
  function AgeString() {
1845
1852
  var _this3;
1846
1853
 
1847
1854
  _classCallCheck(this, AgeString);
1848
1855
 
1849
- _this3 = _super5.call(this, "AS");
1856
+ _this3 = _super6.call(this, "AS");
1850
1857
  _this3.maxLength = 4;
1851
- _this3.padByte = "20";
1858
+ _this3.padByte = 0x20;
1852
1859
  _this3.fixed = true;
1853
1860
  _this3.defaultValue = "";
1854
1861
  return _this3;
1855
1862
  }
1856
1863
 
1857
1864
  return _createClass(AgeString);
1858
- }(StringRepresentation);
1865
+ }(AsciiStringRepresentation);
1859
1866
 
1860
- var AttributeTag = /*#__PURE__*/function (_ValueRepresentation3) {
1861
- _inherits(AttributeTag, _ValueRepresentation3);
1867
+ var AttributeTag = /*#__PURE__*/function (_ValueRepresentation4) {
1868
+ _inherits(AttributeTag, _ValueRepresentation4);
1862
1869
 
1863
- var _super6 = _createSuper(AttributeTag);
1870
+ var _super7 = _createSuper(AttributeTag);
1864
1871
 
1865
1872
  function AttributeTag() {
1866
1873
  var _this4;
1867
1874
 
1868
1875
  _classCallCheck(this, AttributeTag);
1869
1876
 
1870
- _this4 = _super6.call(this, "AT");
1877
+ _this4 = _super7.call(this, "AT");
1871
1878
  _this4.maxLength = 4;
1872
1879
  _this4.valueLength = 4;
1873
- _this4.padByte = "00";
1880
+ _this4.padByte = 0;
1874
1881
  _this4.fixed = true;
1875
1882
  return _this4;
1876
1883
  }
@@ -1878,9 +1885,7 @@ var AttributeTag = /*#__PURE__*/function (_ValueRepresentation3) {
1878
1885
  _createClass(AttributeTag, [{
1879
1886
  key: "readBytes",
1880
1887
  value: function readBytes(stream) {
1881
- var group = stream.readUint16(),
1882
- element = stream.readUint16();
1883
- return tagFromNumbers(group, element).value;
1888
+ return Tag.readTag(stream).value;
1884
1889
  }
1885
1890
  }, {
1886
1891
  key: "writeBytes",
@@ -1892,49 +1897,48 @@ var AttributeTag = /*#__PURE__*/function (_ValueRepresentation3) {
1892
1897
  return AttributeTag;
1893
1898
  }(ValueRepresentation);
1894
1899
 
1895
- var DateValue = /*#__PURE__*/function (_StringRepresentation4) {
1896
- _inherits(DateValue, _StringRepresentation4);
1900
+ var DateValue = /*#__PURE__*/function (_AsciiStringRepresent4) {
1901
+ _inherits(DateValue, _AsciiStringRepresent4);
1897
1902
 
1898
- var _super7 = _createSuper(DateValue);
1903
+ var _super8 = _createSuper(DateValue);
1899
1904
 
1900
1905
  function DateValue(value) {
1901
1906
  var _this5;
1902
1907
 
1903
1908
  _classCallCheck(this, DateValue);
1904
1909
 
1905
- _this5 = _super7.call(this, "DA", value);
1910
+ _this5 = _super8.call(this, "DA", value);
1906
1911
  _this5.maxLength = 18;
1907
- _this5.padByte = "20"; //this.fixed = true;
1912
+ _this5.padByte = 0x20; //this.fixed = true;
1908
1913
 
1909
1914
  _this5.defaultValue = "";
1910
1915
  return _this5;
1911
1916
  }
1912
1917
 
1913
1918
  return _createClass(DateValue);
1914
- }(StringRepresentation);
1919
+ }(AsciiStringRepresentation);
1915
1920
 
1916
- var DecimalString = /*#__PURE__*/function (_StringRepresentation5) {
1917
- _inherits(DecimalString, _StringRepresentation5);
1921
+ var DecimalString = /*#__PURE__*/function (_AsciiStringRepresent5) {
1922
+ _inherits(DecimalString, _AsciiStringRepresent5);
1918
1923
 
1919
- var _super8 = _createSuper(DecimalString);
1924
+ var _super9 = _createSuper(DecimalString);
1920
1925
 
1921
1926
  function DecimalString() {
1922
1927
  var _this6;
1923
1928
 
1924
1929
  _classCallCheck(this, DecimalString);
1925
1930
 
1926
- _this6 = _super8.call(this, "DS");
1931
+ _this6 = _super9.call(this, "DS");
1927
1932
  _this6.maxLength = 16;
1928
- _this6.padByte = "20";
1933
+ _this6.padByte = 0x20;
1929
1934
  return _this6;
1930
1935
  }
1931
1936
 
1932
1937
  _createClass(DecimalString, [{
1933
1938
  key: "readBytes",
1934
1939
  value: function readBytes(stream, length) {
1935
- var BACKSLASH = String.fromCharCode(0x5c); //return this.readNullPaddedString(stream, length).trim();
1936
-
1937
- var ds = stream.readString(length);
1940
+ var BACKSLASH = String.fromCharCode(0x5c);
1941
+ var ds = stream.readAsciiString(length);
1938
1942
  ds = ds.replace(/[^0-9.\\\-+e]/gi, "");
1939
1943
 
1940
1944
  if (ds.indexOf(BACKSLASH) !== -1) {
@@ -1977,40 +1981,40 @@ var DecimalString = /*#__PURE__*/function (_StringRepresentation5) {
1977
1981
  }]);
1978
1982
 
1979
1983
  return DecimalString;
1980
- }(StringRepresentation);
1984
+ }(AsciiStringRepresentation);
1981
1985
 
1982
- var DateTime = /*#__PURE__*/function (_StringRepresentation6) {
1983
- _inherits(DateTime, _StringRepresentation6);
1986
+ var DateTime = /*#__PURE__*/function (_AsciiStringRepresent6) {
1987
+ _inherits(DateTime, _AsciiStringRepresent6);
1984
1988
 
1985
- var _super9 = _createSuper(DateTime);
1989
+ var _super10 = _createSuper(DateTime);
1986
1990
 
1987
1991
  function DateTime() {
1988
1992
  var _this8;
1989
1993
 
1990
1994
  _classCallCheck(this, DateTime);
1991
1995
 
1992
- _this8 = _super9.call(this, "DT");
1996
+ _this8 = _super10.call(this, "DT");
1993
1997
  _this8.maxLength = 26;
1994
- _this8.padByte = "20";
1998
+ _this8.padByte = 0x20;
1995
1999
  return _this8;
1996
2000
  }
1997
2001
 
1998
2002
  return _createClass(DateTime);
1999
- }(StringRepresentation);
2003
+ }(AsciiStringRepresentation);
2000
2004
 
2001
- var FloatingPointSingle = /*#__PURE__*/function (_ValueRepresentation4) {
2002
- _inherits(FloatingPointSingle, _ValueRepresentation4);
2005
+ var FloatingPointSingle = /*#__PURE__*/function (_ValueRepresentation5) {
2006
+ _inherits(FloatingPointSingle, _ValueRepresentation5);
2003
2007
 
2004
- var _super10 = _createSuper(FloatingPointSingle);
2008
+ var _super11 = _createSuper(FloatingPointSingle);
2005
2009
 
2006
2010
  function FloatingPointSingle() {
2007
2011
  var _this9;
2008
2012
 
2009
2013
  _classCallCheck(this, FloatingPointSingle);
2010
2014
 
2011
- _this9 = _super10.call(this, "FL");
2015
+ _this9 = _super11.call(this, "FL");
2012
2016
  _this9.maxLength = 4;
2013
- _this9.padByte = "00";
2017
+ _this9.padByte = 0;
2014
2018
  _this9.fixed = true;
2015
2019
  _this9.defaultValue = 0.0;
2016
2020
  return _this9;
@@ -2031,19 +2035,19 @@ var FloatingPointSingle = /*#__PURE__*/function (_ValueRepresentation4) {
2031
2035
  return FloatingPointSingle;
2032
2036
  }(ValueRepresentation);
2033
2037
 
2034
- var FloatingPointDouble = /*#__PURE__*/function (_ValueRepresentation5) {
2035
- _inherits(FloatingPointDouble, _ValueRepresentation5);
2038
+ var FloatingPointDouble = /*#__PURE__*/function (_ValueRepresentation6) {
2039
+ _inherits(FloatingPointDouble, _ValueRepresentation6);
2036
2040
 
2037
- var _super11 = _createSuper(FloatingPointDouble);
2041
+ var _super12 = _createSuper(FloatingPointDouble);
2038
2042
 
2039
2043
  function FloatingPointDouble() {
2040
2044
  var _this10;
2041
2045
 
2042
2046
  _classCallCheck(this, FloatingPointDouble);
2043
2047
 
2044
- _this10 = _super11.call(this, "FD");
2048
+ _this10 = _super12.call(this, "FD");
2045
2049
  _this10.maxLength = 8;
2046
- _this10.padByte = "00";
2050
+ _this10.padByte = 0;
2047
2051
  _this10.fixed = true;
2048
2052
  _this10.defaultValue = 0.0;
2049
2053
  return _this10;
@@ -2064,19 +2068,19 @@ var FloatingPointDouble = /*#__PURE__*/function (_ValueRepresentation5) {
2064
2068
  return FloatingPointDouble;
2065
2069
  }(ValueRepresentation);
2066
2070
 
2067
- var IntegerString = /*#__PURE__*/function (_StringRepresentation7) {
2068
- _inherits(IntegerString, _StringRepresentation7);
2071
+ var IntegerString = /*#__PURE__*/function (_AsciiStringRepresent7) {
2072
+ _inherits(IntegerString, _AsciiStringRepresent7);
2069
2073
 
2070
- var _super12 = _createSuper(IntegerString);
2074
+ var _super13 = _createSuper(IntegerString);
2071
2075
 
2072
2076
  function IntegerString() {
2073
2077
  var _this11;
2074
2078
 
2075
2079
  _classCallCheck(this, IntegerString);
2076
2080
 
2077
- _this11 = _super12.call(this, "IS");
2081
+ _this11 = _super13.call(this, "IS");
2078
2082
  _this11.maxLength = 12;
2079
- _this11.padByte = "20";
2083
+ _this11.padByte = 0x20;
2080
2084
  return _this11;
2081
2085
  }
2082
2086
 
@@ -2084,7 +2088,7 @@ var IntegerString = /*#__PURE__*/function (_StringRepresentation7) {
2084
2088
  key: "readBytes",
2085
2089
  value: function readBytes(stream, length) {
2086
2090
  var BACKSLASH = String.fromCharCode(0x5c);
2087
- var is = stream.readString(length).trim();
2091
+ var is = stream.readAsciiString(length).trim();
2088
2092
  is = is.replace(/[^0-9.\\\-+e]/gi, "");
2089
2093
 
2090
2094
  if (is.indexOf(BACKSLASH) !== -1) {
@@ -2117,75 +2121,73 @@ var IntegerString = /*#__PURE__*/function (_StringRepresentation7) {
2117
2121
  }]);
2118
2122
 
2119
2123
  return IntegerString;
2120
- }(StringRepresentation);
2124
+ }(AsciiStringRepresentation);
2121
2125
 
2122
- var LongString = /*#__PURE__*/function (_StringRepresentation8) {
2123
- _inherits(LongString, _StringRepresentation8);
2126
+ var LongString = /*#__PURE__*/function (_EncodedStringReprese) {
2127
+ _inherits(LongString, _EncodedStringReprese);
2124
2128
 
2125
- var _super13 = _createSuper(LongString);
2129
+ var _super14 = _createSuper(LongString);
2126
2130
 
2127
2131
  function LongString() {
2128
2132
  var _this13;
2129
2133
 
2130
2134
  _classCallCheck(this, LongString);
2131
2135
 
2132
- _this13 = _super13.call(this, "LO");
2136
+ _this13 = _super14.call(this, "LO");
2133
2137
  _this13.maxCharLength = 64;
2134
- _this13.padByte = "20";
2138
+ _this13.padByte = 0x20;
2135
2139
  return _this13;
2136
2140
  }
2137
2141
 
2138
2142
  _createClass(LongString, [{
2139
2143
  key: "readBytes",
2140
2144
  value: function readBytes(stream, length) {
2141
- //return this.readNullPaddedString(stream, length).trim();
2142
- return stream.readString(length).trim();
2145
+ return stream.readEncodedString(length).trim();
2143
2146
  }
2144
2147
  }]);
2145
2148
 
2146
2149
  return LongString;
2147
- }(StringRepresentation);
2150
+ }(EncodedStringRepresentation);
2148
2151
 
2149
- var LongText = /*#__PURE__*/function (_StringRepresentation9) {
2150
- _inherits(LongText, _StringRepresentation9);
2152
+ var LongText = /*#__PURE__*/function (_EncodedStringReprese2) {
2153
+ _inherits(LongText, _EncodedStringReprese2);
2151
2154
 
2152
- var _super14 = _createSuper(LongText);
2155
+ var _super15 = _createSuper(LongText);
2153
2156
 
2154
2157
  function LongText() {
2155
2158
  var _this14;
2156
2159
 
2157
2160
  _classCallCheck(this, LongText);
2158
2161
 
2159
- _this14 = _super14.call(this, "LT");
2162
+ _this14 = _super15.call(this, "LT");
2160
2163
  _this14.maxCharLength = 10240;
2161
- _this14.padByte = "20";
2164
+ _this14.padByte = 0x20;
2162
2165
  return _this14;
2163
2166
  }
2164
2167
 
2165
2168
  _createClass(LongText, [{
2166
2169
  key: "readBytes",
2167
2170
  value: function readBytes(stream, length) {
2168
- //return rtrim(this.readNullPaddedString(stream, length));
2169
- return rtrim(stream.readString(length));
2171
+ return rtrim(stream.readEncodedString(length));
2170
2172
  }
2171
2173
  }]);
2172
2174
 
2173
2175
  return LongText;
2174
- }(StringRepresentation);
2176
+ }(EncodedStringRepresentation);
2175
2177
 
2176
- var PersonName = /*#__PURE__*/function (_StringRepresentation10) {
2177
- _inherits(PersonName, _StringRepresentation10);
2178
+ var PersonName = /*#__PURE__*/function (_EncodedStringReprese3) {
2179
+ _inherits(PersonName, _EncodedStringReprese3);
2178
2180
 
2179
- var _super15 = _createSuper(PersonName);
2181
+ var _super16 = _createSuper(PersonName);
2180
2182
 
2181
2183
  function PersonName() {
2182
2184
  var _this15;
2183
2185
 
2184
2186
  _classCallCheck(this, PersonName);
2185
2187
 
2186
- _this15 = _super15.call(this, "PN");
2188
+ _this15 = _super16.call(this, "PN");
2187
2189
  _this15.maxLength = null;
2188
- _this15.padByte = "20";
2190
+ _this15.padByte = 0x20;
2189
2191
  return _this15;
2190
2192
  }
2191
2193
 
@@ -2220,54 +2222,52 @@ var PersonName = /*#__PURE__*/function (_StringRepresentation10) {
2220
2222
  }, {
2221
2223
  key: "readBytes",
2222
2224
  value: function readBytes(stream, length) {
2223
- //return rtrim(this.readNullPaddedString(stream, length));
2224
- return rtrim(stream.readString(length));
2225
+ return rtrim(stream.readEncodedString(length));
2225
2226
  }
2226
2227
  }]);
2227
2228
 
2228
2229
  return PersonName;
2229
- }(StringRepresentation);
2230
+ }(EncodedStringRepresentation);
2230
2231
 
2231
- var ShortString = /*#__PURE__*/function (_StringRepresentation11) {
2232
- _inherits(ShortString, _StringRepresentation11);
2232
+ var ShortString = /*#__PURE__*/function (_EncodedStringReprese4) {
2233
+ _inherits(ShortString, _EncodedStringReprese4);
2233
2234
 
2234
- var _super16 = _createSuper(ShortString);
2235
+ var _super17 = _createSuper(ShortString);
2235
2236
 
2236
2237
  function ShortString() {
2237
2238
  var _this16;
2238
2239
 
2239
2240
  _classCallCheck(this, ShortString);
2240
2241
 
2241
- _this16 = _super16.call(this, "SH");
2242
+ _this16 = _super17.call(this, "SH");
2242
2243
  _this16.maxCharLength = 16;
2243
- _this16.padByte = "20";
2244
+ _this16.padByte = 0x20;
2244
2245
  return _this16;
2245
2246
  }
2246
2247
 
2247
2248
  _createClass(ShortString, [{
2248
2249
  key: "readBytes",
2249
2250
  value: function readBytes(stream, length) {
2250
- //return this.readNullPaddedString(stream, length).trim();
2251
- return stream.readString(length).trim();
2251
+ return stream.readEncodedString(length).trim();
2252
2252
  }
2253
2253
  }]);
2254
2254
 
2255
2255
  return ShortString;
2256
- }(StringRepresentation);
2256
+ }(EncodedStringRepresentation);
2257
2257
 
2258
- var SignedLong = /*#__PURE__*/function (_ValueRepresentation6) {
2259
- _inherits(SignedLong, _ValueRepresentation6);
2258
+ var SignedLong = /*#__PURE__*/function (_ValueRepresentation7) {
2259
+ _inherits(SignedLong, _ValueRepresentation7);
2260
2260
 
2261
- var _super17 = _createSuper(SignedLong);
2261
+ var _super18 = _createSuper(SignedLong);
2262
2262
 
2263
2263
  function SignedLong() {
2264
2264
  var _this17;
2265
2265
 
2266
2266
  _classCallCheck(this, SignedLong);
2267
2267
 
2268
- _this17 = _super17.call(this, "SL");
2268
+ _this17 = _super18.call(this, "SL");
2269
2269
  _this17.maxLength = 4;
2270
- _this17.padByte = "00";
2270
+ _this17.padByte = 0;
2271
2271
  _this17.fixed = true;
2272
2272
  _this17.defaultValue = 0;
2273
2273
  return _this17;
@@ -2288,19 +2288,19 @@ var SignedLong = /*#__PURE__*/function (_ValueRepresentation6) {
2288
2288
  return SignedLong;
2289
2289
  }(ValueRepresentation);
2290
2290
 
2291
- var SequenceOfItems = /*#__PURE__*/function (_ValueRepresentation7) {
2292
- _inherits(SequenceOfItems, _ValueRepresentation7);
2291
+ var SequenceOfItems = /*#__PURE__*/function (_ValueRepresentation8) {
2292
+ _inherits(SequenceOfItems, _ValueRepresentation8);
2293
2293
 
2294
- var _super18 = _createSuper(SequenceOfItems);
2294
+ var _super19 = _createSuper(SequenceOfItems);
2295
2295
 
2296
2296
  function SequenceOfItems() {
2297
2297
  var _this18;
2298
2298
 
2299
2299
  _classCallCheck(this, SequenceOfItems);
2300
2300
 
2301
- _this18 = _super18.call(this, "SQ");
2301
+ _this18 = _super19.call(this, "SQ");
2302
2302
  _this18.maxLength = null;
2303
- _this18.padByte = "00";
2303
+ _this18.padByte = 0;
2304
2304
  _this18.noMultiple = true;
2305
2305
  return _this18;
2306
2306
  }
@@ -2317,7 +2317,7 @@ var SequenceOfItems = /*#__PURE__*/function (_ValueRepresentation7) {
2317
2317
  /* eslint-disable-next-line no-constant-condition */
2318
2318
 
2319
2319
  while (true) {
2320
- var tag = readTag(stream),
2320
+ var tag = Tag.readTag(stream),
2321
2321
  length = null;
2322
2322
  read += 4;
2323
2323
 
@@ -2388,7 +2388,9 @@ var SequenceOfItems = /*#__PURE__*/function (_ValueRepresentation7) {
2388
2388
 
2389
2389
  read += toRead;
2390
2390
  if (undef) stream.increment(8);
2391
- var items = DicomMessage.read(itemStream, syntax);
2391
+
2392
+ var items = DicomMessage._read(itemStream, syntax);
2393
+
2392
2394
  elements.push(items);
2393
2395
  }
2394
2396
 
@@ -2442,20 +2444,20 @@ var SequenceOfItems = /*#__PURE__*/function (_ValueRepresentation7) {
2442
2444
  return SequenceOfItems;
2443
2445
  }(ValueRepresentation);
2444
2446
 
2445
- var SignedShort = /*#__PURE__*/function (_ValueRepresentation8) {
2446
- _inherits(SignedShort, _ValueRepresentation8);
2447
+ var SignedShort = /*#__PURE__*/function (_ValueRepresentation9) {
2448
+ _inherits(SignedShort, _ValueRepresentation9);
2447
2449
 
2448
- var _super19 = _createSuper(SignedShort);
2450
+ var _super20 = _createSuper(SignedShort);
2449
2451
 
2450
2452
  function SignedShort() {
2451
2453
  var _this19;
2452
2454
 
2453
2455
  _classCallCheck(this, SignedShort);
2454
2456
 
2455
- _this19 = _super19.call(this, "SS");
2457
+ _this19 = _super20.call(this, "SS");
2456
2458
  _this19.maxLength = 2;
2457
2459
  _this19.valueLength = 2;
2458
- _this19.padByte = "00";
2460
+ _this19.padByte = 0;
2459
2461
  _this19.fixed = true;
2460
2462
  _this19.defaultValue = 0;
2461
2463
  return _this19;
@@ -2476,126 +2478,124 @@ var SignedShort = /*#__PURE__*/function (_ValueRepresentation8) {
2476
2478
  return SignedShort;
2477
2479
  }(ValueRepresentation);
2478
2480
 
2479
- var ShortText = /*#__PURE__*/function (_StringRepresentation12) {
2480
- _inherits(ShortText, _StringRepresentation12);
2481
+ var ShortText = /*#__PURE__*/function (_EncodedStringReprese5) {
2482
+ _inherits(ShortText, _EncodedStringReprese5);
2481
2483
 
2482
- var _super20 = _createSuper(ShortText);
2484
+ var _super21 = _createSuper(ShortText);
2483
2485
 
2484
2486
  function ShortText() {
2485
2487
  var _this20;
2486
2488
 
2487
2489
  _classCallCheck(this, ShortText);
2488
2490
 
2489
- _this20 = _super20.call(this, "ST");
2491
+ _this20 = _super21.call(this, "ST");
2490
2492
  _this20.maxCharLength = 1024;
2491
- _this20.padByte = "20";
2493
+ _this20.padByte = 0x20;
2492
2494
  return _this20;
2493
2495
  }
2494
2496
 
2495
2497
  _createClass(ShortText, [{
2496
2498
  key: "readBytes",
2497
2499
  value: function readBytes(stream, length) {
2498
- //return rtrim(this.readNullPaddedString(stream, length));
2499
- return rtrim(stream.readString(length));
2500
+ return rtrim(stream.readEncodedString(length));
2500
2501
  }
2501
2502
  }]);
2502
2503
 
2503
2504
  return ShortText;
2504
- }(StringRepresentation);
2505
+ }(EncodedStringRepresentation);
2505
2506
 
2506
- var TimeValue = /*#__PURE__*/function (_StringRepresentation13) {
2507
- _inherits(TimeValue, _StringRepresentation13);
2507
+ var TimeValue = /*#__PURE__*/function (_AsciiStringRepresent8) {
2508
+ _inherits(TimeValue, _AsciiStringRepresent8);
2508
2509
 
2509
- var _super21 = _createSuper(TimeValue);
2510
+ var _super22 = _createSuper(TimeValue);
2510
2511
 
2511
2512
  function TimeValue() {
2512
2513
  var _this21;
2513
2514
 
2514
2515
  _classCallCheck(this, TimeValue);
2515
2516
 
2516
- _this21 = _super21.call(this, "TM");
2517
+ _this21 = _super22.call(this, "TM");
2517
2518
  _this21.maxLength = 14;
2518
- _this21.padByte = "20";
2519
+ _this21.padByte = 0x20;
2519
2520
  return _this21;
2520
2521
  }
2521
2522
 
2522
2523
  _createClass(TimeValue, [{
2523
2524
  key: "readBytes",
2524
2525
  value: function readBytes(stream, length) {
2525
- return rtrim(stream.readString(length));
2526
+ return rtrim(stream.readAsciiString(length));
2526
2527
  }
2527
2528
  }]);
2528
2529
 
2529
2530
  return TimeValue;
2530
- }(StringRepresentation);
2531
+ }(AsciiStringRepresentation);
2531
2532
 
2532
- var UnlimitedCharacters = /*#__PURE__*/function (_StringRepresentation14) {
2533
- _inherits(UnlimitedCharacters, _StringRepresentation14);
2533
+ var UnlimitedCharacters = /*#__PURE__*/function (_EncodedStringReprese6) {
2534
+ _inherits(UnlimitedCharacters, _EncodedStringReprese6);
2534
2535
 
2535
- var _super22 = _createSuper(UnlimitedCharacters);
2536
+ var _super23 = _createSuper(UnlimitedCharacters);
2536
2537
 
2537
2538
  function UnlimitedCharacters() {
2538
2539
  var _this22;
2539
2540
 
2540
2541
  _classCallCheck(this, UnlimitedCharacters);
2541
2542
 
2542
- _this22 = _super22.call(this, "UC");
2543
+ _this22 = _super23.call(this, "UC");
2543
2544
  _this22.maxLength = null;
2544
2545
  _this22.multi = true;
2545
- _this22.padByte = "20";
2546
+ _this22.padByte = 0x20;
2546
2547
  return _this22;
2547
2548
  }
2548
2549
 
2549
2550
  _createClass(UnlimitedCharacters, [{
2550
2551
  key: "readBytes",
2551
2552
  value: function readBytes(stream, length) {
2552
- return rtrim(stream.readString(length));
2553
+ return rtrim(stream.readEncodedString(length));
2553
2554
  }
2554
2555
  }]);
2555
2556
 
2556
2557
  return UnlimitedCharacters;
2557
- }(StringRepresentation);
2558
+ }(EncodedStringRepresentation);
2558
2559
 
2559
- var UnlimitedText = /*#__PURE__*/function (_StringRepresentation15) {
2560
- _inherits(UnlimitedText, _StringRepresentation15);
2560
+ var UnlimitedText = /*#__PURE__*/function (_EncodedStringReprese7) {
2561
+ _inherits(UnlimitedText, _EncodedStringReprese7);
2561
2562
 
2562
- var _super23 = _createSuper(UnlimitedText);
2563
+ var _super24 = _createSuper(UnlimitedText);
2563
2564
 
2564
2565
  function UnlimitedText() {
2565
2566
  var _this23;
2566
2567
 
2567
2568
  _classCallCheck(this, UnlimitedText);
2568
2569
 
2569
- _this23 = _super23.call(this, "UT");
2570
+ _this23 = _super24.call(this, "UT");
2570
2571
  _this23.maxLength = null;
2571
- _this23.padByte = "20";
2572
+ _this23.padByte = 0x20;
2572
2573
  return _this23;
2573
2574
  }
2574
2575
 
2575
2576
  _createClass(UnlimitedText, [{
2576
2577
  key: "readBytes",
2577
2578
  value: function readBytes(stream, length) {
2578
- //return this.readNullPaddedString(stream, length);
2579
- return rtrim(stream.readString(length));
2579
+ return rtrim(stream.readEncodedString(length));
2580
2580
  }
2581
2581
  }]);
2582
2582
 
2583
2583
  return UnlimitedText;
2584
- }(StringRepresentation);
2584
+ }(EncodedStringRepresentation);
2585
2585
 
2586
- var UnsignedShort = /*#__PURE__*/function (_ValueRepresentation9) {
2587
- _inherits(UnsignedShort, _ValueRepresentation9);
2586
+ var UnsignedShort = /*#__PURE__*/function (_ValueRepresentation10) {
2587
+ _inherits(UnsignedShort, _ValueRepresentation10);
2588
2588
 
2589
- var _super24 = _createSuper(UnsignedShort);
2589
+ var _super25 = _createSuper(UnsignedShort);
2590
2590
 
2591
2591
  function UnsignedShort() {
2592
2592
  var _this24;
2593
2593
 
2594
2594
  _classCallCheck(this, UnsignedShort);
2595
2595
 
2596
- _this24 = _super24.call(this, "US");
2596
+ _this24 = _super25.call(this, "US");
2597
2597
  _this24.maxLength = 2;
2598
- _this24.padByte = "00";
2598
+ _this24.padByte = 0;
2599
2599
  _this24.fixed = true;
2600
2600
  _this24.defaultValue = 0;
2601
2601
  return _this24;
@@ -2616,19 +2616,19 @@ var UnsignedShort = /*#__PURE__*/function (_ValueRepresentation9) {
2616
2616
  return UnsignedShort;
2617
2617
  }(ValueRepresentation);
2618
2618
 
2619
- var UnsignedLong = /*#__PURE__*/function (_ValueRepresentation10) {
2620
- _inherits(UnsignedLong, _ValueRepresentation10);
2619
+ var UnsignedLong = /*#__PURE__*/function (_ValueRepresentation11) {
2620
+ _inherits(UnsignedLong, _ValueRepresentation11);
2621
2621
 
2622
- var _super25 = _createSuper(UnsignedLong);
2622
+ var _super26 = _createSuper(UnsignedLong);
2623
2623
 
2624
2624
  function UnsignedLong() {
2625
2625
  var _this25;
2626
2626
 
2627
2627
  _classCallCheck(this, UnsignedLong);
2628
2628
 
2629
- _this25 = _super25.call(this, "UL");
2629
+ _this25 = _super26.call(this, "UL");
2630
2630
  _this25.maxLength = 4;
2631
- _this25.padByte = "00";
2631
+ _this25.padByte = 0;
2632
2632
  _this25.fixed = true;
2633
2633
  _this25.defaultValue = 0;
2634
2634
  return _this25;
@@ -2649,19 +2649,19 @@ var UnsignedLong = /*#__PURE__*/function (_ValueRepresentation10) {
2649
2649
  return UnsignedLong;
2650
2650
  }(ValueRepresentation);
2651
2651
 
2652
- var UniqueIdentifier = /*#__PURE__*/function (_StringRepresentation16) {
2653
- _inherits(UniqueIdentifier, _StringRepresentation16);
2652
+ var UniqueIdentifier = /*#__PURE__*/function (_AsciiStringRepresent9) {
2653
+ _inherits(UniqueIdentifier, _AsciiStringRepresent9);
2654
2654
 
2655
- var _super26 = _createSuper(UniqueIdentifier);
2655
+ var _super27 = _createSuper(UniqueIdentifier);
2656
2656
 
2657
2657
  function UniqueIdentifier() {
2658
2658
  var _this26;
2659
2659
 
2660
2660
  _classCallCheck(this, UniqueIdentifier);
2661
2661
 
2662
- _this26 = _super26.call(this, "UI");
2662
+ _this26 = _super27.call(this, "UI");
2663
2663
  _this26.maxLength = 64;
2664
- _this26.padByte = "00";
2664
+ _this26.padByte = 0;
2665
2665
  return _this26;
2666
2666
  }
2667
2667
 
@@ -2689,47 +2689,47 @@ var UniqueIdentifier = /*#__PURE__*/function (_StringRepresentation16) {
2689
2689
  }]);
2690
2690
 
2691
2691
  return UniqueIdentifier;
2692
- }(StringRepresentation);
2692
+ }(AsciiStringRepresentation);
2693
2693
 
2694
- var UniversalResource = /*#__PURE__*/function (_StringRepresentation17) {
2695
- _inherits(UniversalResource, _StringRepresentation17);
2694
+ var UniversalResource = /*#__PURE__*/function (_AsciiStringRepresent10) {
2695
+ _inherits(UniversalResource, _AsciiStringRepresent10);
2696
2696
 
2697
- var _super27 = _createSuper(UniversalResource);
2697
+ var _super28 = _createSuper(UniversalResource);
2698
2698
 
2699
2699
  function UniversalResource() {
2700
2700
  var _this27;
2701
2701
 
2702
2702
  _classCallCheck(this, UniversalResource);
2703
2703
 
2704
- _this27 = _super27.call(this, "UR");
2704
+ _this27 = _super28.call(this, "UR");
2705
2705
  _this27.maxLength = null;
2706
- _this27.padByte = "20";
2706
+ _this27.padByte = 0x20;
2707
2707
  return _this27;
2708
2708
  }
2709
2709
 
2710
2710
  _createClass(UniversalResource, [{
2711
2711
  key: "readBytes",
2712
2712
  value: function readBytes(stream, length) {
2713
- return stream.readString(length);
2713
+ return stream.readAsciiString(length);
2714
2714
  }
2715
2715
  }]);
2716
2716
 
2717
2717
  return UniversalResource;
2718
- }(StringRepresentation);
2718
+ }(AsciiStringRepresentation);
2719
2719
 
2720
2720
  var UnknownValue = /*#__PURE__*/function (_BinaryRepresentation) {
2721
2721
  _inherits(UnknownValue, _BinaryRepresentation);
2722
2722
 
2723
- var _super28 = _createSuper(UnknownValue);
2723
+ var _super29 = _createSuper(UnknownValue);
2724
2724
 
2725
2725
  function UnknownValue() {
2726
2726
  var _this28;
2727
2727
 
2728
2728
  _classCallCheck(this, UnknownValue);
2729
2729
 
2730
- _this28 = _super28.call(this, "UN");
2730
+ _this28 = _super29.call(this, "UN");
2731
2731
  _this28.maxLength = null;
2732
- _this28.padByte = "00";
2732
+ _this28.padByte = 0;
2733
2733
  _this28.noMultiple = true;
2734
2734
  return _this28;
2735
2735
  }
@@ -2740,16 +2740,16 @@ var UnknownValue = /*#__PURE__*/function (_BinaryRepresentation) {
2740
2740
  var OtherWordString = /*#__PURE__*/function (_BinaryRepresentation2) {
2741
2741
  _inherits(OtherWordString, _BinaryRepresentation2);
2742
2742
 
2743
- var _super29 = _createSuper(OtherWordString);
2743
+ var _super30 = _createSuper(OtherWordString);
2744
2744
 
2745
2745
  function OtherWordString() {
2746
2746
  var _this29;
2747
2747
 
2748
2748
  _classCallCheck(this, OtherWordString);
2749
2749
 
2750
- _this29 = _super29.call(this, "OW");
2750
+ _this29 = _super30.call(this, "OW");
2751
2751
  _this29.maxLength = null;
2752
- _this29.padByte = "00";
2752
+ _this29.padByte = 0;
2753
2753
  _this29.noMultiple = true;
2754
2754
  return _this29;
2755
2755
  }
@@ -2760,16 +2760,16 @@ var OtherWordString = /*#__PURE__*/function (_BinaryRepresentation2) {
2760
2760
  var OtherByteString = /*#__PURE__*/function (_BinaryRepresentation3) {
2761
2761
  _inherits(OtherByteString, _BinaryRepresentation3);
2762
2762
 
2763
- var _super30 = _createSuper(OtherByteString);
2763
+ var _super31 = _createSuper(OtherByteString);
2764
2764
 
2765
2765
  function OtherByteString() {
2766
2766
  var _this30;
2767
2767
 
2768
2768
  _classCallCheck(this, OtherByteString);
2769
2769
 
2770
- _this30 = _super30.call(this, "OB");
2770
+ _this30 = _super31.call(this, "OB");
2771
2771
  _this30.maxLength = null;
2772
- _this30.padByte = "00";
2772
+ _this30.padByte = 0;
2773
2773
  _this30.noMultiple = true;
2774
2774
  return _this30;
2775
2775
  }
@@ -2780,16 +2780,16 @@ var OtherByteString = /*#__PURE__*/function (_BinaryRepresentation3) {
2780
2780
  var OtherDoubleString = /*#__PURE__*/function (_BinaryRepresentation4) {
2781
2781
  _inherits(OtherDoubleString, _BinaryRepresentation4);
2782
2782
 
2783
- var _super31 = _createSuper(OtherDoubleString);
2783
+ var _super32 = _createSuper(OtherDoubleString);
2784
2784
 
2785
2785
  function OtherDoubleString() {
2786
2786
  var _this31;
2787
2787
 
2788
2788
  _classCallCheck(this, OtherDoubleString);
2789
2789
 
2790
- _this31 = _super31.call(this, "OD");
2790
+ _this31 = _super32.call(this, "OD");
2791
2791
  _this31.maxLength = null;
2792
- _this31.padByte = "00";
2792
+ _this31.padByte = 0;
2793
2793
  _this31.noMultiple = true;
2794
2794
  return _this31;
2795
2795
  }
@@ -2800,26 +2800,64 @@ var OtherDoubleString = /*#__PURE__*/function (_BinaryRepresentation4) {
2800
2800
  var OtherFloatString = /*#__PURE__*/function (_BinaryRepresentation5) {
2801
2801
  _inherits(OtherFloatString, _BinaryRepresentation5);
2802
2802
 
2803
- var _super32 = _createSuper(OtherFloatString);
2803
+ var _super33 = _createSuper(OtherFloatString);
2804
2804
 
2805
2805
  function OtherFloatString() {
2806
2806
  var _this32;
2807
2807
 
2808
2808
  _classCallCheck(this, OtherFloatString);
2809
2809
 
2810
- _this32 = _super32.call(this, "OF");
2810
+ _this32 = _super33.call(this, "OF");
2811
2811
  _this32.maxLength = null;
2812
- _this32.padByte = "00";
2812
+ _this32.padByte = 0;
2813
2813
  _this32.noMultiple = true;
2814
2814
  return _this32;
2815
2815
  }
2816
2816
 
2817
2817
  return _createClass(OtherFloatString);
2818
- }(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
+ };
2819
2853
 
2820
2854
  var IMPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2";
2821
2855
  var EXPLICIT_LITTLE_ENDIAN = "1.2.840.10008.1.2.1";
2822
2856
 
2857
+ function paddingLeft(paddingValue, string) {
2858
+ return String(paddingValue + string).slice(-paddingValue.length);
2859
+ }
2860
+
2823
2861
  var Tag = /*#__PURE__*/function () {
2824
2862
  function Tag(value) {
2825
2863
  _classCallCheck(this, Tag);
@@ -2900,12 +2938,12 @@ var Tag = /*#__PURE__*/function () {
2900
2938
  written += 4;
2901
2939
  } else {
2902
2940
  if (vr.isExplicit()) {
2903
- stream.writeString(vr.type);
2904
- stream.writeHex("0000");
2941
+ stream.writeAsciiString(vr.type);
2942
+ stream.writeUint16(0);
2905
2943
  stream.writeUint32(valueLength);
2906
2944
  written += 8;
2907
2945
  } else {
2908
- stream.writeString(vr.type);
2946
+ stream.writeAsciiString(vr.type);
2909
2947
  stream.writeUint16(valueLength);
2910
2948
  written += 4;
2911
2949
  }
@@ -3377,6 +3415,10 @@ var IMPLICIT_LITTLE_ENDIAN$1 = "1.2.840.10008.1.2";
3377
3415
  var EXPLICIT_LITTLE_ENDIAN$1 = "1.2.840.10008.1.2.1";
3378
3416
  var EXPLICIT_BIG_ENDIAN = "1.2.840.10008.1.2.2";
3379
3417
  var singleVRs$1 = ["SQ", "OF", "OW", "OB", "UN", "LT"];
3418
+ var encodingMapping = {
3419
+ "iso-ir-192": "utf-8",
3420
+ "": "latin1"
3421
+ };
3380
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"];
3381
3423
 
3382
3424
  var DicomMessage = /*#__PURE__*/function () {
@@ -3389,12 +3431,65 @@ var DicomMessage = /*#__PURE__*/function () {
3389
3431
  value: function read(bufferStream, syntax, ignoreErrors) {
3390
3432
  var untilTag = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
3391
3433
  var includeUntilTagValue = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
3434
+ console.warn("DicomMessage.read to be deprecated after dcmjs 0.24.x");
3435
+ return this._read(bufferStream, syntax, {
3436
+ ignoreErrors: ignoreErrors,
3437
+ untilTag: untilTag,
3438
+ includeUntilTagValue: includeUntilTagValue
3439
+ });
3440
+ }
3441
+ }, {
3442
+ key: "readTag",
3443
+ value: function readTag(bufferStream, syntax) {
3444
+ var untilTag = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
3445
+ var includeUntilTagValue = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
3446
+ console.warn("DicomMessage.readTag to be deprecated after dcmjs 0.24.x");
3447
+ return this._readTag(bufferStream, syntax, {
3448
+ untilTag: untilTag,
3449
+ includeUntilTagValue: includeUntilTagValue
3450
+ });
3451
+ }
3452
+ }, {
3453
+ key: "_read",
3454
+ value: function _read(bufferStream, syntax) {
3455
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
3456
+ ignoreErrors: false,
3457
+ untilTag: null,
3458
+ includeUntilTagValue: false
3459
+ };
3460
+ var ignoreErrors = options.ignoreErrors,
3461
+ untilTag = options.untilTag;
3392
3462
  var dict = {};
3393
3463
 
3394
3464
  try {
3395
3465
  while (!bufferStream.end()) {
3396
- var readInfo = DicomMessage.readTag(bufferStream, syntax, untilTag, includeUntilTagValue);
3466
+ var readInfo = DicomMessage._readTag(bufferStream, syntax, options);
3467
+
3397
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
+
3398
3493
  dict[cleanTagString] = {
3399
3494
  vr: readInfo.vr.type,
3400
3495
  Value: readInfo.values
@@ -3435,29 +3530,34 @@ var DicomMessage = /*#__PURE__*/function () {
3435
3530
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
3436
3531
  ignoreErrors: false,
3437
3532
  untilTag: null,
3438
- includeUntilTagValue: false
3533
+ includeUntilTagValue: false,
3534
+ noCopy: false
3439
3535
  };
3440
- var ignoreErrors = options.ignoreErrors,
3441
- untilTag = options.untilTag,
3442
- includeUntilTagValue = options.includeUntilTagValue;
3443
- var stream = new ReadBufferStream(buffer),
3536
+ var stream = new ReadBufferStream(buffer, null, {
3537
+ noCopy: options.noCopy
3538
+ }),
3444
3539
  useSyntax = EXPLICIT_LITTLE_ENDIAN$1;
3445
3540
  stream.reset();
3446
3541
  stream.increment(128);
3447
3542
 
3448
- if (stream.readString(4) !== "DICM") {
3543
+ if (stream.readAsciiString(4) !== "DICM") {
3449
3544
  throw new Error("Invalid a dicom file");
3450
3545
  }
3451
3546
 
3452
- var el = DicomMessage.readTag(stream, useSyntax),
3547
+ var el = DicomMessage._readTag(stream, useSyntax),
3453
3548
  metaLength = el.values[0]; //read header buffer
3454
3549
 
3550
+
3455
3551
  var metaStream = stream.more(metaLength);
3456
- var metaHeader = DicomMessage.read(metaStream, useSyntax, ignoreErrors); //get the syntax
3552
+
3553
+ var metaHeader = DicomMessage._read(metaStream, useSyntax, options); //get the syntax
3554
+
3457
3555
 
3458
3556
  var mainSyntax = metaHeader["00020010"].Value[0];
3459
3557
  mainSyntax = DicomMessage._normalizeSyntax(mainSyntax);
3460
- var objects = DicomMessage.read(stream, mainSyntax, ignoreErrors, untilTag, includeUntilTagValue);
3558
+
3559
+ var objects = DicomMessage._read(stream, mainSyntax, options);
3560
+
3461
3561
  var dicomDict = new DicomDict(metaHeader);
3462
3562
  dicomDict.dict = objects;
3463
3563
  return dicomDict;
@@ -3483,17 +3583,19 @@ var DicomMessage = /*#__PURE__*/function () {
3483
3583
  return written;
3484
3584
  }
3485
3585
  }, {
3486
- key: "readTag",
3487
- value: function readTag(stream, syntax) {
3488
- var untilTag = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
3489
- var includeUntilTagValue = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
3586
+ key: "_readTag",
3587
+ value: function _readTag(stream, syntax) {
3588
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
3589
+ untilTag: null,
3590
+ includeUntilTagValue: false
3591
+ };
3592
+ var untilTag = options.untilTag,
3593
+ includeUntilTagValue = options.includeUntilTagValue;
3490
3594
  var implicit = syntax == IMPLICIT_LITTLE_ENDIAN$1 ? true : false,
3491
3595
  isLittleEndian = syntax == IMPLICIT_LITTLE_ENDIAN$1 || syntax == EXPLICIT_LITTLE_ENDIAN$1 ? true : false;
3492
3596
  var oldEndian = stream.isLittleEndian;
3493
3597
  stream.setEndian(isLittleEndian);
3494
- var group = stream.readUint16(),
3495
- element = stream.readUint16(),
3496
- tag = tagFromNumbers(group, element);
3598
+ var tag = Tag.readTag(stream);
3497
3599
 
3498
3600
  if (untilTag === tag.toCleanString() && untilTag !== null) {
3499
3601
  if (!includeUntilTagValue) {
@@ -3532,7 +3634,7 @@ var DicomMessage = /*#__PURE__*/function () {
3532
3634
 
3533
3635
  vr = ValueRepresentation.createByTypeString(vrType);
3534
3636
  } else {
3535
- vrType = stream.readString(2);
3637
+ vrType = stream.readVR();
3536
3638
  vr = ValueRepresentation.createByTypeString(vrType);
3537
3639
 
3538
3640
  if (vr.isExplicit()) {
@@ -3617,8 +3719,8 @@ var DicomDict = /*#__PURE__*/function () {
3617
3719
  };
3618
3720
  var metaSyntax = EXPLICIT_LITTLE_ENDIAN$2;
3619
3721
  var fileStream = new WriteBufferStream(4096, true);
3620
- fileStream.writeHex("00".repeat(128));
3621
- fileStream.writeString("DICM");
3722
+ fileStream.writeUint8Repeat(0, 128);
3723
+ fileStream.writeAsciiString("DICM");
3622
3724
  var metaStream = new WriteBufferStream(1024);
3623
3725
 
3624
3726
  if (!this.meta["00020010"]) {