allow getting the writer offset and the length of both readers and writers

This commit is contained in:
Holly Stubbs 2023-11-07 00:14:03 +00:00
parent 63a3e5c73b
commit c1e43e2937
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
3 changed files with 13 additions and 1 deletions

View file

@ -14,6 +14,10 @@ export class ReaderBase {
return this.offset; return this.offset;
} }
public get length() {
return this.buffer.length;
}
public readBuffer(bytes:number) { public readBuffer(bytes:number) {
const value = this.buffer.subarray(this.offset, this.offset + bytes); const value = this.buffer.subarray(this.offset, this.offset + bytes);
this.offset += bytes; this.offset += bytes;

View file

@ -14,6 +14,14 @@ export class WriterBase {
this.resizable = size === 0; this.resizable = size === 0;
} }
public get writeOffset() {
return this.offset;
}
public get length() {
return this.buffer.length;
}
public toBuffer() { public toBuffer() {
return this.buffer; return this.buffer;
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "bufferstuff", "name": "bufferstuff",
"version": "1.4.0", "version": "1.4.1",
"description": "A set of utility classes for reading and writing binary data in NodeJS and the browser", "description": "A set of utility classes for reading and writing binary data in NodeJS and the browser",
"main": "./lib/index.js", "main": "./lib/index.js",
"types": "./lib/index.d.ts", "types": "./lib/index.d.ts",