Files
gemini-cli/packages/core/src/context/system/NodeFileSystem.ts
T

57 lines
1.3 KiB
TypeScript
Raw Normal View History

2026-04-06 22:17:32 +00:00
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import * as fs from 'node:fs';
2026-04-06 22:27:32 +00:00
import * as fsPromises from 'node:fs/promises';
2026-04-06 22:17:32 +00:00
import * as path from 'node:path';
import type { IFileSystem } from './IFileSystem.js';
export class NodeFileSystem implements IFileSystem {
existsSync(p: string): boolean {
return fs.existsSync(p);
}
2026-04-07 04:46:04 +00:00
2026-04-06 22:17:32 +00:00
statSyncSize(p: string): number {
return fs.statSync(p).size;
}
2026-04-07 04:46:04 +00:00
2026-04-06 22:17:32 +00:00
readFileSync(p: string, encoding: 'utf8'): string {
return fs.readFileSync(p, encoding);
}
2026-04-07 04:46:04 +00:00
2026-04-06 22:27:32 +00:00
writeFileSync(p: string, data: string | Buffer, encoding?: 'utf-8'): void {
if (Buffer.isBuffer(data)) {
2026-04-07 04:46:04 +00:00
fs.writeFileSync(p, data);
2026-04-06 22:27:32 +00:00
} else {
2026-04-07 04:46:04 +00:00
fs.writeFileSync(p, data, encoding);
2026-04-06 22:27:32 +00:00
}
2026-04-06 22:17:32 +00:00
}
2026-04-07 04:46:04 +00:00
2026-04-06 22:17:32 +00:00
appendFileSync(p: string, data: string, encoding: 'utf-8'): void {
fs.appendFileSync(p, data, encoding);
}
2026-04-07 04:46:04 +00:00
2026-04-06 22:17:32 +00:00
mkdirSync(p: string, options?: { recursive?: boolean }): void {
fs.mkdirSync(p, options);
}
2026-04-06 22:27:32 +00:00
async writeFile(p: string, data: string | Buffer): Promise<void> {
await fsPromises.writeFile(p, data);
}
async mkdir(p: string, options?: { recursive?: boolean }): Promise<void> {
await fsPromises.mkdir(p, options);
}
2026-04-06 22:17:32 +00:00
join(...paths: string[]): string {
return path.join(...paths);
}
dirname(p: string): string {
return path.dirname(p);
}
}