MCPcopy Index your code
hub / github.com/cloudflare/agents / FileSystemStateBackend

Class FileSystemStateBackend

packages/shell/src/memory.ts:85–483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85export class FileSystemStateBackend implements StateBackend {
86 readonly fs: FileSystem;
87
88 constructor(fsOrOptions: FileSystem | FileSystemStateBackendOptions = {}) {
89 if (isFileSystem(fsOrOptions)) {
90 this.fs = fsOrOptions;
91 } else {
92 this.fs = fsOrOptions.fs ?? new InMemoryFs(fsOrOptions.files);
93 }
94 }
95
96 async getCapabilities(): Promise<StateCapabilities> {
97 return {
98 chmod: true,
99 utimes: true,
100 hardLinks: true
101 };
102 }
103
104 async readFile(path: string): Promise<string> {
105 return this.fs.readFile(path);
106 }
107
108 async readFileBytes(path: string): Promise<Uint8Array> {
109 return this.fs.readFileBytes(path);
110 }
111
112 async writeFile(path: string, content: string): Promise<void> {
113 await this.fs.writeFile(path, content);
114 }
115
116 async writeFileBytes(path: string, content: Uint8Array): Promise<void> {
117 await this.fs.writeFileBytes(path, content);
118 }
119
120 async appendFile(path: string, content: string | Uint8Array): Promise<void> {
121 await this.fs.appendFile(path, content);
122 }
123
124 async readJson(path: string): Promise<unknown> {
125 return parseJsonFileContent(await this.readFile(path), path);
126 }
127
128 async writeJson(
129 path: string,
130 value: unknown,
131 options?: StateJsonWriteOptions
132 ): Promise<void> {
133 await this.writeFile(
134 path,
135 stringifyJsonFileContent(value, path, options?.spaces)
136 );
137 }
138
139 async queryJson(path: string, query: string): Promise<unknown> {
140 return queryJsonValue(await this.readJson(path), query);
141 }
142

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected