All files / src CursorDataView.ts

100% Statements 10/10
0% Branches 0/1
100% Functions 3/3
100% Lines 10/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    1x   4x   4x       197x 197x 197x       7x 7x 7x 7x      
import {EncodingValue} from './interfaces/EncodingValue';
 
export class CursorDataView {
  dataview: DataView;
  index = 0;
  constructor(input: ArrayBuffer) {
    this.dataview = new DataView(input);
  }
 
  read() {
    const uint = this.dataview.getUint8(this.index);
    this.index += 1;
    return uint;
  }
 
  readString(length: number, encoding: EncodingValue = 'hex') {
    const buffer = this.dataview.buffer.slice(this.index, this.index + length);
    const value = Buffer.from(buffer).toString(encoding);
    this.index += length;
    return value;
  }
}