Skip to content

Commit 3ce8c59

Browse files
committed
add getter for .arrayBuffer
1 parent 719bd31 commit 3ce8c59

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "a package designed to facilitate the reading and writing of binary data.",
44
"module": "./dist/BinaryStream.js",
55
"types": "./dist/BinaryStream.d.ts",
6-
"version": "1.1.3",
6+
"version": "1.1.4",
77
"type": "module",
88
"keywords": [
99
"binary",

src/BinaryStream.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,16 @@ class BinaryStream {
119119
* @param offset The optional offset to write the data at.
120120
* @returns The updated BinaryStream instance.
121121
*/
122-
write(buffer: Uint8Array | number[], offset?: number): this {
122+
write(stream: BinaryStream, offset?: number): this;
123+
write(buffer: ArrayBuffer, offset?: number): this;
124+
write(buffer: Uint8Array | number[], offset?: number): this;
125+
write(buffer: any, offset?: number): this {
126+
if (buffer instanceof ArrayBuffer) {
127+
buffer = new Uint8Array(buffer);
128+
} else if (buffer instanceof BinaryStream) {
129+
buffer = buffer.buffer;
130+
}
131+
123132
const { start, end } = this.increaseOffset(buffer.length, offset);
124133
if (end > this.length) {
125134
this.resize(end, false);
@@ -169,6 +178,10 @@ class BinaryStream {
169178
return this.view.buffer.byteLength;
170179
}
171180

181+
get arrayBuffer(): ArrayBuffer {
182+
return this.view.buffer;
183+
}
184+
172185
/**
173186
* Creates a Blob from the buffer.
174187
* @param type The MIME type of the Blob.

0 commit comments

Comments
 (0)