Skip to content

Commit

Permalink
feat: Add stdout/stderr Fd class
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Dec 5, 2023
1 parent 9289c4c commit b31fba0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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";

0 comments on commit b31fba0

Please sign in to comment.