Skip to content

Commit

Permalink
Implement setSize.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Jul 14, 2024
1 parent 4f730c7 commit 3638808
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/wasi-virt.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,19 @@ class Descriptor {
return new WriteStream(this.entry, offset);
}

setSize(size) {
if (this.entry instanceof Directory)
throw 'is-directory';
size = Number(size);
if (size > this.entry.data.length) {
const newData = new Uint8Array(size);
newData.set(this.entry.data);
this.entry.data = newData;
} else if (size < this.entry.data.length) {
this.entry.data = this.entry.data.subarray(0, size);
}
}

readDirectory() {
return new DirectoryEntryStream(this.entry);
}
Expand Down

0 comments on commit 3638808

Please sign in to comment.