Skip to content

Commit 01a56a9

Browse files
committed
fix(web-host): fix tee command file overwriting behavior #12
The `Descriptor#write` method was incorrectly trying to preserve existing file content when writing, which broke the `tee` command's ability to overwrite files. The fix simplifies the logic: instead of concatenating new data with existing file content, the method now directly replaces the file's buffer. This matches the expected behavior of file writes - when writing to a file, it should overwrite the content, not append to it. - Remove buffer concatenation logic in writeViaStream - Implement direct buffer replacement for proper file overwriting - Fixes tee command behavior on both new and existing files Issue: #12
1 parent ce56bee commit 01a56a9

File tree

1 file changed

+3
-4
lines changed
  • packages/web-host/overrides/@bytecodealliance/preview2-shim/lib/browser

1 file changed

+3
-4
lines changed

packages/web-host/overrides/@bytecodealliance/preview2-shim/lib/browser/filesystem.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ class Descriptor {
110110
let offset = Number(_offset);
111111
return new OutputStream({
112112
write (buf) {
113-
const newSource = new Uint8Array(buf.byteLength + entry.source.byteLength);
114-
newSource.set(entry.source, 0);
115-
newSource.set(buf, offset);
113+
const newSource = new Uint8Array(buf.byteLength);
114+
newSource.set(buf, 0);
116115
offset += buf.byteLength;
117116
entry.source = newSource;
118117
return buf.byteLength;
@@ -196,7 +195,7 @@ class Descriptor {
196195
statusChangeTimestamp: timeZero,
197196
}
198197
}
199-
198+
200199
statAt(_pathFlags, path) {
201200
const entry = getChildEntry(this.#entry, path, { create: false, directory: false });
202201
let type = 'unknown', size = BigInt(0);

0 commit comments

Comments
 (0)