Skip to content

Commit

Permalink
Merge pull request #16 from marcosc90/fix-ab-transfer
Browse files Browse the repository at this point in the history
fix: use buffer.transfer() if available
  • Loading branch information
e3dio authored Jul 9, 2024
2 parents 3086472 + 397fc83 commit cce062a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packbytes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export class PackBytes {
}
checkSize(bytes) {
if (bytes + this.offset > this.dataview.byteLength) {
if (false) this.dataview = new DataView(this.dataview.buffer.transfer(this.dataview.byteLength * 2));
if (this.dataview.buffer.transfer) this.dataview = new DataView(this.dataview.buffer.transfer(this.dataview.byteLength * 2));
else { // backwards compatible for <= Node v20
const arraybuffer = new ArrayBuffer(this.dataview.byteLength * 2);
new Uint8Array(arraybuffer).set(new Uint8Array(this.dataview.buffer));
Expand Down

0 comments on commit cce062a

Please sign in to comment.