Skip to content

Commit

Permalink
allow getting the writer offset and the length of both readers and wr…
Browse files Browse the repository at this point in the history
…iters
  • Loading branch information
tgpholly committed Nov 7, 2023
1 parent 63a3e5c commit c1e43e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions base/ReaderBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export class ReaderBase {
return this.offset;
}

public get length() {
return this.buffer.length;
}

public readBuffer(bytes:number) {
const value = this.buffer.subarray(this.offset, this.offset + bytes);
this.offset += bytes;
Expand Down
8 changes: 8 additions & 0 deletions base/WriterBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ export class WriterBase {
this.resizable = size === 0;
}

public get writeOffset() {
return this.offset;
}

public get length() {
return this.buffer.length;
}

public toBuffer() {
return this.buffer;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"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",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down

0 comments on commit c1e43e2

Please sign in to comment.