All files / src/common/buffer buffer-array.ts

90.9% Statements 10/11
75% Branches 3/4
100% Functions 5/5
90% Lines 9/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 2968x 68x   1507x     3205x       856x       2382x       842x     842x       1507x      
import { hexToBytes } from '../encoding-hex';
import { concatByteArrays } from '../index';
 
export class BufferArray {
  _value: Uint8Array[] = [];
  get value() {
    return this._value;
  }
 
  appendHexString(hexString: string) {
    this.value.push(hexToBytes(hexString));
  }
 
  push(buffer: Uint8Array) {
    return this._value.push(buffer);
  }
 
  appendByte(octet: number) {
    Iif (!Number.isInteger(octet) || octet < 0 || octet > 255) {
      throw new Error(`Value ${octet} is not a valid byte`);
    }
    this.value.push(Uint8Array.from([octet]));
  }
 
  concatBuffer(): Uint8Array {
    return concatByteArrays(this.value);
  }
}