Skip to content

feat: Add stdout/stderr Fd class #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
23 changes: 23 additions & 0 deletions src/fs_fd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,29 @@ export class OpenFile extends Fd {
}
}

/**
* A file that is opened as a standard output/error stream.
*/
export class Stdout extends Fd {
constructor() {
super();
}

fd_filestat_get() {
const filestat = new wasi.Filestat(
wasi.FILETYPE_CHARACTER_DEVICE,
BigInt(0),
);
return { ret: 0, filestat };
}

fd_fdstat_get() {
const fdstat = new wasi.Fdstat(wasi.FILETYPE_CHARACTER_DEVICE, 0);
fdstat.fs_rights_base = BigInt(wasi.RIGHTS_FD_WRITE);
return { ret: 0, fdstat };
}
}

export class OpenSyncOPFSFile extends Fd {
file: SyncOPFSFile;
position: bigint = 0n;
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export {
OpenDirectory,
OpenSyncOPFSFile,
PreopenDirectory,
Stdout,
} from "./fs_fd.js";
export { strace } from "./strace.js";