Skip to content

Commit

Permalink
Fix wasi-drive read/resize in @runno/wasi (#244)
Browse files Browse the repository at this point in the history
* Fix pread not using offset for end index; use subarray to avoid copy; fix resize failing on first write larger than 4096

* Wrong offset ref
  • Loading branch information
jabinb authored Jul 11, 2023
1 parent bd7016a commit 79bcbd1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/wasi/lib/wasi/wasi-drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,13 @@ class OpenFile {
}

read(bytes: number) {
const ret = this.buffer.slice(this.offset, bytes);
const ret = this.buffer.subarray(this.offset, this.offset + bytes);
this._offset += BigInt(ret.length);
return ret;
}

pread(bytes: number, offset: number) {
return this.buffer.slice(offset, bytes);
return this.buffer.subarray(offset, offset + bytes);
}

write(data: Uint8Array) {
Expand Down Expand Up @@ -637,7 +637,7 @@ class OpenFile {
let underBuffer: ArrayBuffer;

if (this.buffer.buffer.byteLength === 0) {
underBuffer = new ArrayBuffer(1024);
underBuffer = new ArrayBuffer(requiredBytes < 1024 ? 1024 : requiredBytes * 2);
} else if (requiredBytes > this.buffer.buffer.byteLength * 2) {
underBuffer = new ArrayBuffer(requiredBytes * 2);
} else {
Expand Down

0 comments on commit 79bcbd1

Please sign in to comment.