blob: 3e4cd30f019d9f914521f7d99d274575c25c6af2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import fs from 'fs/promises';
import protobuf from 'protobufjs';
/**
* 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>;
/**
* Read and parse a proto file
*
* @param filePath - The path to the file to read
* @returns The file content as a JSON string
*/
readProtoFile(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 readProtoFile(filePath: string): Promise<string> {
const root = await protobuf.load(filePath);
return JSON.stringify(root.toJSON(), null, 2);
}
async writeTextFile(filePath: string, content: string): Promise<void> {
await fs.writeFile(filePath, content, 'utf-8');
}
}
|