@dcmjs-org/dcmjs 1.0.0-beta.6 → 1.0.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/dcmjs.js CHANGED
@@ -7738,13 +7738,34 @@
7738
7738
  }
7739
7739
  return createBuffer.buffer;
7740
7740
  }
7741
+
7742
+ /**
7743
+ * Returns the index of the buffer holding byte `start`, or undefined if
7744
+ * no buffer holds it. Buffers are only ever appended, so offsets[] is
7745
+ * increasing and a binary search finds it. A linear scan here made
7746
+ * writing a sequence of many items quadratic, since every write near the
7747
+ * end of a stream scanned all of its buffers.
7748
+ * https://github.com/dcmjs-org/dcmjs/issues/629
7749
+ */
7741
7750
  }, {
7742
7751
  key: "findStart",
7743
7752
  value: function findStart() {
7744
7753
  var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
7745
- for (var index = 0; index < this.buffers.length; index++) {
7746
- if (start >= this.offsets[index] && start < this.offsets[index] + this.lengths[index]) {
7747
- return index;
7754
+ // Refuses NaN and negatives; NaN fails both comparisons below and
7755
+ // would otherwise be reported as found.
7756
+ if (!(start >= 0)) {
7757
+ return;
7758
+ }
7759
+ var low = 0;
7760
+ var high = this.offsets.length - 1;
7761
+ while (low <= high) {
7762
+ var mid = low + high >> 1;
7763
+ if (start < this.offsets[mid]) {
7764
+ high = mid - 1;
7765
+ } else if (start >= this.offsets[mid] + this.lengths[mid]) {
7766
+ low = mid + 1;
7767
+ } else {
7768
+ return mid;
7748
7769
  }
7749
7770
  }
7750
7771
  }
@@ -9739,6 +9760,11 @@
9739
9760
  value: function isBinary() {
9740
9761
  return this._isBinary;
9741
9762
  }
9763
+ }, {
9764
+ key: "isString",
9765
+ value: function isString() {
9766
+ return false;
9767
+ }
9742
9768
  }, {
9743
9769
  key: "allowMultiple",
9744
9770
  value: function allowMultiple() {
@@ -9838,6 +9864,13 @@
9838
9864
  var readOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
9839
9865
  forceStoreRaw: false
9840
9866
  };
9867
+ // a zero-length string element has no value, not one empty value
9868
+ if (length === 0 && this.isString()) {
9869
+ return {
9870
+ rawValue: [],
9871
+ value: []
9872
+ };
9873
+ }
9841
9874
  if (this.fixed && this.maxLength) {
9842
9875
  if (!length) return {
9843
9876
  rawValue: this.defaultValue,
@@ -10064,6 +10097,11 @@
10064
10097
  }
10065
10098
  _inherits(AsciiStringRepresentation, _ValueRepresentation);
10066
10099
  return _createClass(AsciiStringRepresentation, [{
10100
+ key: "isString",
10101
+ value: function isString() {
10102
+ return true;
10103
+ }
10104
+ }, {
10067
10105
  key: "readBytes",
10068
10106
  value: function readBytes(stream, length) {
10069
10107
  return stream.readAsciiString(length);
@@ -10083,6 +10121,11 @@
10083
10121
  }
10084
10122
  _inherits(EncodedStringRepresentation, _ValueRepresentation2);
10085
10123
  return _createClass(EncodedStringRepresentation, [{
10124
+ key: "isString",
10125
+ value: function isString() {
10126
+ return true;
10127
+ }
10128
+ }, {
10086
10129
  key: "readBytes",
10087
10130
  value: function readBytes(stream, length) {
10088
10131
  return stream.readEncodedString(length);