diff options
| author | Conrad Irwin <[email protected]> | 2025-08-18 16:29:45 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-18 22:29:45 +0000 |
| commit | fb3ceb0da4e2cd636013c2c36a9c0016c01aa47f (patch) | |
| tree | 7aa43846dd88bd5acdb8898b0ccd2e685f2d5ece /packages/core/src/services/fileSystemService.ts | |
| parent | 4394b6ab4fc86637b07fcd26b9a790c627d1e065 (diff) | |
Read and write files through Zed (#6169)
Co-authored-by: Agus Zubiaga <[email protected]>
Diffstat (limited to 'packages/core/src/services/fileSystemService.ts')
| -rw-r--r-- | packages/core/src/services/fileSystemService.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/packages/core/src/services/fileSystemService.ts b/packages/core/src/services/fileSystemService.ts new file mode 100644 index 00000000..e2f30cf4 --- /dev/null +++ b/packages/core/src/services/fileSystemService.ts @@ -0,0 +1,41 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import fs from 'fs/promises'; + +/** + * Interface for file system operations that may be delegated to different implementations + */ +export interface FileSystemService { + /** + * Read text content from a file + * + * @param filePath - The path to the file to read + * @returns The file content as a string + */ + readTextFile(filePath: string): Promise<string>; + + /** + * Write text content to a file + * + * @param filePath - The path to the file to write + * @param content - The content to write + */ + writeTextFile(filePath: string, content: string): Promise<void>; +} + +/** + * Standard file system implementation + */ +export class StandardFileSystemService implements FileSystemService { + async readTextFile(filePath: string): Promise<string> { + return fs.readFile(filePath, 'utf-8'); + } + + async writeTextFile(filePath: string, content: string): Promise<void> { + await fs.writeFile(filePath, content, 'utf-8'); + } +} |
