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
@@ -14,18 +14,21 @@ 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, 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 content = this.files.get(path);
|
||||
if (content === undefined) {
|
||||
throw new Error(`File not found: ${path}`);
|
||||
}
|
||||
const encoding = typeof options === 'string' ? options : options?.encoding;
|
||||
return encoding ? content : new TextEncoder().encode(content);
|
||||
}
|
||||
|
||||
async writeFile(path: string, data: string | Uint8Array, _encoding?: string): Promise<void> {
|
||||
async writeFile(path: string, data: string | Uint8Array, _options?: string | { encoding?: string }): Promise<void> {
|
||||
const content = typeof data === 'string' ? data : new TextDecoder().decode(data);
|
||||
this.files.set(path, content);
|
||||
}
|
||||
|
||||
@@ -41,15 +41,18 @@ 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, 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 content = this.files.get(path);
|
||||
if (content === undefined) {
|
||||
throw new Error(`File not found: ${path}`);
|
||||
}
|
||||
|
||||
const encoding = typeof options === 'string' ? options : options?.encoding;
|
||||
// If no encoding specified, return Uint8Array
|
||||
if (!encoding) {
|
||||
// For binary files, return mock binary data with null bytes
|
||||
@@ -70,7 +73,7 @@ class MockFS implements JSRuntimeFS {
|
||||
return content;
|
||||
}
|
||||
|
||||
async writeFile(path: string, data: string | Uint8Array, _encoding?: string): Promise<void> {
|
||||
async writeFile(path: string, data: string | Uint8Array, _options?: string | { encoding?: string }): Promise<void> {
|
||||
const content = typeof data === 'string' ? data : new TextDecoder().decode(data);
|
||||
this.files.set(path, content);
|
||||
}
|
||||
|
||||
@@ -13,18 +13,21 @@ 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, 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 content = this.files.get(path);
|
||||
if (content === undefined) {
|
||||
throw new Error(`File not found: ${path}`);
|
||||
}
|
||||
const encoding = typeof options === 'string' ? options : options?.encoding;
|
||||
return encoding ? content : new TextEncoder().encode(content);
|
||||
}
|
||||
|
||||
async writeFile(path: string, data: string | Uint8Array, _encoding?: string): Promise<void> {
|
||||
async writeFile(path: string, data: string | Uint8Array, _options?: string | { encoding?: string }): Promise<void> {
|
||||
const content = typeof data === 'string' ? data : new TextDecoder().decode(data);
|
||||
this.files.set(path, content);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user