Skip to content

Commit 3638808

Browse files
committed
Implement setSize.
1 parent 4f730c7 commit 3638808

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/wasi-virt.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,19 @@ class Descriptor {
300300
return new WriteStream(this.entry, offset);
301301
}
302302

303+
setSize(size) {
304+
if (this.entry instanceof Directory)
305+
throw 'is-directory';
306+
size = Number(size);
307+
if (size > this.entry.data.length) {
308+
const newData = new Uint8Array(size);
309+
newData.set(this.entry.data);
310+
this.entry.data = newData;
311+
} else if (size < this.entry.data.length) {
312+
this.entry.data = this.entry.data.subarray(0, size);
313+
}
314+
}
315+
303316
readDirectory() {
304317
return new DirectoryEntryStream(this.entry);
305318
}

0 commit comments

Comments
 (0)