MCPcopy Create free account
hub / github.com/dethcrypto/dethcode / FileSystem

Function FileSystem

packages/ethereum-viewer/src/fs/fileSystem.ts:8–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6 * Facade on top of MemFS file system provider for more convenient programmatic use.
7 */
8export const FileSystem = () => {
9 const fs = new MemFS();
10 const encoder = new TextEncoder();
11 const decoder = new TextDecoder();
12
13 return {
14 register(context: vscode.ExtensionContext) {
15 context.subscriptions.push(
16 vscode.workspace.registerFileSystemProvider("memfs", fs, {
17 isCaseSensitive: true,
18 })
19 );
20 },
21 writeFile(path: string, content: string) {
22 if (!path.startsWith("/")) path = "/" + path;
23
24 // const uri = vscode.Uri.from({ scheme: "memfs", path: path });
25 const uri = vscode.Uri.from({ scheme: "memfs", path: path });
26
27 fs.writeFile(uri, encoder.encode(content), {
28 create: true,
29 overwrite: true,
30 });
31 },
32 readFile(path: string): string {
33 if (!path.startsWith("/")) path = "/" + path;
34
35 const buffer = fs.readFile(
36 vscode.Uri.from({ scheme: "memfs", path: path })
37 );
38
39 return decoder.decode(buffer);
40 },
41 onDidChangeFile: fs.onDidChangeFile.bind(fs),
42 };
43};
44
45export type FileSystem = ReturnType<typeof FileSystem>;

Callers 2

extension.tsFile · 0.90
fileSystem.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected