Working with File System
When js-dos player successfully starts, the DOSBox command interface is available. You can get it from the event:
Dos(/*element*/, {
url: /* bundle url */,
onEvent: ("ci-ready", ci: CommandInterface) {
// now ci s ready
},
);
With ci you can interact with a DOS file system.
Read file from FS
fsReadFile(file: string): Promise<Uint8Array>;
This function will read the file from the given path and return the promise to Uint8Array.
Write file to FS
fsWriteFile(file: string, contents: ReadableStream<Uint8Array> | Uint8Array): Promise<void>;
This method will write contents into the provided file.
Delete file from FS
fsDeleteFile(file: string): Promise<void>;
Delete file from FS.
Get the whole file tree
You can read the full file system structure by calling:
fsTree(): Promise<FsNode>;
The FsNode contains following:
export interface FsNode {
name: string;
size: number | null;
nodes: FsNode[] | null;
}
name - is a file name
size - size of file in bytes, or
null
in case of directorynodes - children of directory, or
null
in case of file
Advanced: using Emscripten FS API
Emscripten API is even more powerful, but also low level. You can access it only in direct mode.
Last modified: 18 ноября 2024