@dcmjs-org/dcmjs 1.0.0-beta.10 → 1.0.0-beta.11

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
@@ -7661,21 +7661,46 @@
7661
7661
  * Adds the buffer to the end of the current buffers list,
7662
7662
  * updating the size etc.
7663
7663
  *
7664
- * @param {*} buffer
7665
- * @param {*} options.start for the start of the new buffer to use
7666
- * @param {*} options.end for the end of the buffer to use
7667
- * @param {*} options.transfer to transfer the buffer to be owned
7664
+ * A typed array or DataView (for example a Node.js Buffer) adds only the
7665
+ * bytes of the view, and not the full underlying ArrayBuffer. A small
7666
+ * Node.js Buffer is a view of a shared pool, so the full ArrayBuffer
7667
+ * holds bytes of other allocations.
7668
+ *
7669
+ * @param {*} buffer an ArrayBuffer, or a typed array or DataView
7670
+ * @param {*} options.start byte offset for the start of the new buffer
7671
+ * to use, relative to the start of the view, clamped to the view
7672
+ * @param {*} options.end byte offset for the end of the buffer to use,
7673
+ * relative to the start of the view, clamped to the view (an
7674
+ * explicit `end: 0` adds nothing)
7675
+ * @param {*} options.transfer keeps a reference to the ArrayBuffer
7676
+ * instead of a copy, and the caller must not change the buffer
7677
+ * afterwards. It does not detach the buffer. It applies only when the
7678
+ * range covers the whole ArrayBuffer, so a partial view or range is
7679
+ * always copied. The default is true for an ArrayBuffer, and false
7680
+ * for a view, so that a caller can reuse a view.
7668
7681
  */
7669
7682
  }, {
7670
7683
  key: "addBuffer",
7671
7684
  value: function addBuffer(buffer) {
7672
- var _options$transfer;
7685
+ var _options$start, _options$end, _options$transfer;
7673
7686
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
7674
- buffer = buffer.buffer || buffer;
7675
- var start = (options === null || options === void 0 ? void 0 : options.start) || 0;
7676
- var end = (options === null || options === void 0 ? void 0 : options.end) || buffer.byteLength;
7677
- var transfer = (_options$transfer = options === null || options === void 0 ? void 0 : options.transfer) !== null && _options$transfer !== void 0 ? _options$transfer : start === 0 && end === buffer.byteLength;
7678
- if (start === end) {
7687
+ var isView = ArrayBuffer.isView(buffer);
7688
+ var base = 0;
7689
+ var length;
7690
+ if (isView) {
7691
+ base = buffer.byteOffset;
7692
+ length = buffer.byteLength;
7693
+ buffer = buffer.buffer;
7694
+ } else {
7695
+ buffer = buffer.buffer || buffer;
7696
+ length = buffer.byteLength;
7697
+ }
7698
+ var start = base + Math.min(Math.max((_options$start = options === null || options === void 0 ? void 0 : options.start) !== null && _options$start !== void 0 ? _options$start : 0, 0), length);
7699
+ var end = base + Math.min(Math.max((_options$end = options === null || options === void 0 ? void 0 : options.end) !== null && _options$end !== void 0 ? _options$end : length, start - base), length);
7700
+ var whole = start === 0 && end === buffer.byteLength;
7701
+ var transfer = whole && ((_options$transfer = options === null || options === void 0 ? void 0 : options.transfer) !== null && _options$transfer !== void 0 ? _options$transfer : !isView);
7702
+ // NaN fails this comparison too, so a NaN start or end adds nothing
7703
+ if (!(start < end)) {
7679
7704
  return;
7680
7705
  }
7681
7706
  var addBuffer = transfer ? buffer : buffer.slice(start, end);
@@ -8514,13 +8539,14 @@
8514
8539
  }
8515
8540
 
8516
8541
  /**
8517
- * Reads from an async stream delivering to addBuffer.
8542
+ * Reads from an async stream delivering to addBuffer. Each chunk is
8543
+ * copied, also a plain ArrayBuffer, so the producer may reuse it.
8518
8544
  */
8519
8545
  }, {
8520
8546
  key: "fromAsyncStream",
8521
8547
  value: (function () {
8522
8548
  var _fromAsyncStream = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(stream) {
8523
- var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, chunk, ab, _t;
8549
+ var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, chunk, _t;
8524
8550
  return _regeneratorRuntime().wrap(function (_context) {
8525
8551
  while (1) switch (_context.prev = _context.next) {
8526
8552
  case 0:
@@ -8537,8 +8563,9 @@
8537
8563
  break;
8538
8564
  }
8539
8565
  chunk = _step.value;
8540
- ab = chunk.buffer.slice(chunk.byteOffset, chunk.byteOffset + chunk.byteLength);
8541
- this.addBuffer(ab);
8566
+ this.addBuffer(chunk, {
8567
+ transfer: false
8568
+ });
8542
8569
  case 4:
8543
8570
  _iteratorAbruptCompletion = false;
8544
8571
  _context.next = 2;
@@ -8588,12 +8615,20 @@
8588
8615
  * Adds the buffer to the end of the current buffers list,
8589
8616
  * updating the size etc.
8590
8617
  *
8591
- * @param {*} buffer
8592
- * @param {*} options.start for the start of the new buffer to use
8593
- * @param {*} options.end for the end of the buffer to use
8594
- * @param {*} options.transfer to transfer the buffer to be owned
8595
- * Transfer will default true if the entire buffer is being added.
8596
- * It should be set explicitly to false to NOT transfer.
8618
+ * A typed array or DataView (for example a Node.js Buffer) adds only
8619
+ * the bytes of the view, and not the full underlying ArrayBuffer.
8620
+ *
8621
+ * @param {*} buffer an ArrayBuffer, or a typed array or DataView
8622
+ * @param {*} options.start byte offset for the start of the new buffer
8623
+ * to use, relative to the start of the view, clamped to the view
8624
+ * @param {*} options.end byte offset for the end of the buffer to use,
8625
+ * relative to the start of the view, clamped to the view
8626
+ * @param {*} options.transfer keeps a reference to the ArrayBuffer
8627
+ * instead of a copy, and the caller must not change the buffer
8628
+ * afterwards. It does not detach the buffer. It applies only when
8629
+ * the range covers the whole ArrayBuffer, so a partial view or range
8630
+ * is always copied. The default is true for an ArrayBuffer, and
8631
+ * false for a view. Set it to false to force a copy.
8597
8632
  */
8598
8633
  )
8599
8634
  }, {
@@ -8726,14 +8761,8 @@
8726
8761
  if (buffer instanceof BufferStream) {
8727
8762
  _this3.view.from(buffer.view, options);
8728
8763
  _this3.isComplete = true;
8729
- } else if (ArrayBuffer.isView(buffer)) {
8730
- // adopt only the viewed byte range (see the class doc comment)
8731
- _this3.view.addBuffer(buffer.buffer, {
8732
- start: buffer.byteOffset,
8733
- end: buffer.byteOffset + buffer.byteLength
8734
- });
8735
- _this3.isComplete = true;
8736
8764
  } else if (buffer) {
8765
+ // a view adds only its viewed byte range (SplitDataView.addBuffer)
8737
8766
  _this3.view.addBuffer(buffer);
8738
8767
  _this3.isComplete = true;
8739
8768
  }
@@ -12851,7 +12880,9 @@
12851
12880
  * the specification.
12852
12881
  */
12853
12882
 
12854
- var BLOCK_KEY = /^([0-9A-Fa-f]{4}):(.+)$/;
12883
+ // `s`: the creator may hold a line break; PS3.5 6.2 forbids one in LO, but a
12884
+ // reader of real data can get one, and the block must still be written.
12885
+ var BLOCK_KEY = /^([0-9A-Fa-f]{4}):([^]+)$/;
12855
12886
  var ELEMENT_KEY$1 = /^x([0-9A-Fa-f]{2})$/;
12856
12887
  var HEX_TAG = /^[0-9A-Fa-f]{8}$/;
12857
12888