mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Accept options object in JSRuntimeFS
This commit is contained in:
8 files changed
+62
-35
No files matched your search
@@ -26,15 +26,19 @@ class MockFS implements JSRuntimeFS {
|
||||
}
|
||||
|
||||
async readFile(path: string): Promise<Uint8Array>;
|
||||
async readFile(path: string, encoding: 'utf8'): Promise<string>;
|
||||
async readFile(path: string, encoding: string): Promise<string>;
|
||||
async readFile(path: string, encoding?: string): Promise<string | Uint8Array> {
|
||||
async readFile(path: string, options: 'utf8'): Promise<string>;
|
||||
async readFile(path: string, options: string): Promise<string>;
|
||||
async readFile(path: string, options: { encoding: 'utf8' }): Promise<string>;
|
||||
async readFile(path: string, options: { encoding: string }): Promise<string>;
|
||||
async readFile(path: string, options?: string | { encoding?: string }): Promise<string | Uint8Array>;
|
||||
async readFile(path: string, options?: string | { encoding?: string }): Promise<string | Uint8Array> {
|
||||
const file = this.files.get(path);
|
||||
if (!file || file.isDir) throw new Error(`File not found: ${path}`);
|
||||
const encoding = typeof options === 'string' ? options : options?.encoding;
|
||||
return encoding === 'utf8' ? file.content.toString() : new Uint8Array();
|
||||
}
|
||||
|
||||
async writeFile(path: string, data: string | Uint8Array): Promise<void> {
|
||||
async writeFile(path: string, data: string | Uint8Array, _options?: string | { encoding?: string }): Promise<void> {
|
||||
this.files.set(path, { content: data, mtimeMs: Date.now(), isDir: false });
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user