@amazon/vinyl-util 3.2.3-next.20261010160052 → 3.2.3-next.20261013201428

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/dist/index.cjs CHANGED
@@ -40,6 +40,7 @@ var index_exports = {};
40
40
  __export(index_exports, {
41
41
  Abort: () => Abort,
42
42
  AbortError: () => AbortError,
43
+ BitReader: () => BitReader,
43
44
  Browser: () => Browser,
44
45
  BufferError: () => BufferError,
45
46
  BufferReader: () => BufferReader,
@@ -4966,6 +4967,80 @@ async function poll(predicate, options = {}) {
4966
4967
  return result;
4967
4968
  }
4968
4969
 
4970
+ // src/util/buffer/BufferError.ts
4971
+ var BufferError = class _BufferError extends ReportableError {
4972
+ get [Symbol.toStringTag]() {
4973
+ return "BufferError";
4974
+ }
4975
+ constructor(message, origin = ErrorOrigin.MEDIA, level = "fatal" /* FATAL */) {
4976
+ super(message, origin, level);
4977
+ Object.setPrototypeOf(this, _BufferError.prototype);
4978
+ }
4979
+ };
4980
+
4981
+ // src/util/buffer/BitReader.ts
4982
+ var BitReader = class {
4983
+ constructor(data) {
4984
+ __publicField(this, "data", data);
4985
+ /**
4986
+ * The position in bits.
4987
+ */
4988
+ __publicField(this, "position", 0);
4989
+ }
4990
+ /**
4991
+ * The position in bytes, rounded up to the next byte boundary.
4992
+ */
4993
+ get bytePosition() {
4994
+ return Math.ceil(this.position / 8);
4995
+ }
4996
+ /**
4997
+ * The number of bits remaining.
4998
+ */
4999
+ get remaining() {
5000
+ return this.data.length * 8 - this.position;
5001
+ }
5002
+ /**
5003
+ * Moves to the given byte position.
5004
+ */
5005
+ seek(bytePosition) {
5006
+ this.position = bytePosition * 8;
5007
+ }
5008
+ skip(bits) {
5009
+ this.position += bits;
5010
+ }
5011
+ /**
5012
+ * Reads a single bit as a boolean.
5013
+ */
5014
+ readFlag() {
5015
+ return this.readBits(1) === 1;
5016
+ }
5017
+ /**
5018
+ * Reads an unsigned value of `count` bits.
5019
+ */
5020
+ readBits(count) {
5021
+ if (count > this.remaining)
5022
+ throw new BufferError(
5023
+ `Unexpected end of buffer reached at bit: ${this.position}. Reading ${count} bits, ${this.remaining} available.`
5024
+ );
5025
+ let value = 0;
5026
+ for (let i = 0; i < count; i++) {
5027
+ const byte = this.data[this.position >> 3];
5028
+ const bit = byte >> 7 - (this.position & 7) & 1;
5029
+ value = value * 2 + bit;
5030
+ this.position++;
5031
+ }
5032
+ return value;
5033
+ }
5034
+ /**
5035
+ * Reads `count` bytes, which need not be byte aligned.
5036
+ */
5037
+ readBytes(count) {
5038
+ const out = new Uint8Array(count);
5039
+ for (let i = 0; i < count; i++) out[i] = this.readBits(8);
5040
+ return out;
5041
+ }
5042
+ };
5043
+
4969
5044
  // src/util/buffer/buffer.ts
4970
5045
  function bufferToByteStr(buffer) {
4971
5046
  return String.fromCharCode.apply(
@@ -5024,17 +5099,6 @@ function buffersEqual(bufferA, bufferB) {
5024
5099
  return true;
5025
5100
  }
5026
5101
 
5027
- // src/util/buffer/BufferError.ts
5028
- var BufferError = class _BufferError extends ReportableError {
5029
- get [Symbol.toStringTag]() {
5030
- return "BufferError";
5031
- }
5032
- constructor(message, origin = ErrorOrigin.MEDIA, level = "fatal" /* FATAL */) {
5033
- super(message, origin, level);
5034
- Object.setPrototypeOf(this, _BufferError.prototype);
5035
- }
5036
- };
5037
-
5038
5102
  // src/util/buffer/BufferReader.ts
5039
5103
  var BufferReader = class {
5040
5104
  constructor(buffer) {