Skip to content

Commit

Permalink
[polyfill] Write support
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Aug 1, 2020
1 parent 819ddfb commit eda9796
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions rustc.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

get size() {
return BigInt(this.data.byteLength);
return this.data.byteLength;
}

open() {
Expand All @@ -29,7 +29,7 @@
ino: 0n,
file_type: this.file_type,
nlink: 0n,
size: this.size,
size: BigInt(this.size),
atim: 0n,
mtim: 0n,
ctim: 0n,
Expand Down Expand Up @@ -64,7 +64,17 @@
}

write(buffer) {
return -2;
this.file.data.set(
buffer.slice(
0,
this.size - this.file_pos,
), this.file_pos
);
if (this.size - this.file_pos > buffer.byteLength) {
this.file.data = this.file.data.transfer(this.file_pos + buffer.byteLength);
}
this.file_pos += buffer.byteLength;
return 0;
}

stat() {
Expand Down Expand Up @@ -146,24 +156,6 @@
//let wasm = await WebAssembly.compileStreaming(fetch("/rust_out.wasm"));
document.body.innerText = "Instantiating";

function write_le_u32(buf, ptr, num) {
buf[ptr] = num;
buf[ptr + 1] = num >> 8;
buf[ptr + 2] = num >> 16;
buf[ptr + 3] = num >> 24;
}

function write_le_u64(buf, ptr, num) {
buf[ptr] = Number(num);
buf[ptr + 1] = Number(num >> 8n);
buf[ptr + 2] = Number(num >> 16n);
buf[ptr + 3] = Number(num >> 24n);
buf[ptr + 4] = Number(num >> 32n);
buf[ptr + 5] = Number(num >> 40n);
buf[ptr + 6] = Number(num >> 48n);
buf[ptr + 7] = Number(num >> 56n);
}

function fd_err() {
return -1;
}
Expand Down

0 comments on commit eda9796

Please sign in to comment.