Skip to content

Commit

Permalink
add getter for .arrayBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
hcortezr committed Jun 12, 2024
1 parent 719bd31 commit 3ce8c59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "a package designed to facilitate the reading and writing of binary data.",
"module": "./dist/BinaryStream.js",
"types": "./dist/BinaryStream.d.ts",
"version": "1.1.3",
"version": "1.1.4",
"type": "module",
"keywords": [
"binary",
Expand Down
15 changes: 14 additions & 1 deletion src/BinaryStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,16 @@ class BinaryStream {
* @param offset The optional offset to write the data at.
* @returns The updated BinaryStream instance.
*/
write(buffer: Uint8Array | number[], offset?: number): this {
write(stream: BinaryStream, offset?: number): this;
write(buffer: ArrayBuffer, offset?: number): this;
write(buffer: Uint8Array | number[], offset?: number): this;
write(buffer: any, offset?: number): this {
if (buffer instanceof ArrayBuffer) {
buffer = new Uint8Array(buffer);
} else if (buffer instanceof BinaryStream) {
buffer = buffer.buffer;
}

const { start, end } = this.increaseOffset(buffer.length, offset);
if (end > this.length) {
this.resize(end, false);
Expand Down Expand Up @@ -169,6 +178,10 @@ class BinaryStream {
return this.view.buffer.byteLength;
}

get arrayBuffer(): ArrayBuffer {
return this.view.buffer;
}

/**
* Creates a Blob from the buffer.
* @param type The MIME type of the Blob.
Expand Down

0 comments on commit 3ce8c59

Please sign in to comment.