From c1e43e29373407f5bc9e86727dbd23cb3ff084da Mon Sep 17 00:00:00 2001 From: Holly Date: Tue, 7 Nov 2023 00:14:03 +0000 Subject: [PATCH] allow getting the writer offset and the length of both readers and writers --- base/ReaderBase.ts | 4 ++++ base/WriterBase.ts | 8 ++++++++ package.json | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/base/ReaderBase.ts b/base/ReaderBase.ts index 0089b36..eb08d1d 100644 --- a/base/ReaderBase.ts +++ b/base/ReaderBase.ts @@ -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; diff --git a/base/WriterBase.ts b/base/WriterBase.ts index e1eb36c..b9b0436 100644 --- a/base/WriterBase.ts +++ b/base/WriterBase.ts @@ -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; } diff --git a/package.json b/package.json index 2f7c6b1..ec87111 100644 --- a/package.json +++ b/package.json @@ -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",