Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions wasm-wasi-core/src/common/pipeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PipeFileDescriptor extends BaseFileDescriptor {
}

interface Stdin {
read(maxBytesToRead: size): Promise<Uint8Array>;
read(mode: 'max', maxBytesToRead: size): Promise<Uint8Array>;
}

interface Stdout {
Expand Down Expand Up @@ -82,7 +82,7 @@ export function create(deviceId: DeviceId, stdin: Stdin | undefined, stdout: Std
}

const maxBytesToRead = buffers.reduce<number>((prev, current) => prev + current.length, 0);
const result = await stdin.read(maxBytesToRead);
const result = await stdin.read('max', maxBytesToRead);
let offset = 0;
let totalBytesRead = 0;
for (const buffer of buffers) {
Expand Down
6 changes: 2 additions & 4 deletions wasm-wasi-core/src/common/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,12 @@ export abstract class Stream {
if (resultSize + this.chunks[i].byteLength > maxBytes) {
break;
}
resultSize += this.chunks[i].byteLength;
}
const result = new Uint8Array(resultSize);
let offset = 0;
for (let i = 0; i < this.chunks.length; i++) {
while (offset < resultSize) {
const chunk = this.chunks.shift()!;
if (offset + chunk.byteLength > maxBytes) {
break;
}
result.set(chunk, offset);
offset += chunk.byteLength;
this.fillLevel -= chunk.byteLength;
Expand Down