MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / FileSystem

Class FileSystem

src/platform/common/platform/fileSystem.ts:19–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17 */
18@injectable()
19export class FileSystem implements IFileSystem {
20 protected vscfs: vscode.FileSystem;
21 constructor() {
22 this.vscfs = vscode.workspace.fs;
23 }
24
25 // API based on VS Code fs API
26 arePathsSame(path1: vscode.Uri, path2: vscode.Uri): boolean {
27 return uriPath.isEqual(path1, path2);
28 }
29
30 async getFiles(dir: vscode.Uri): Promise<vscode.Uri[]> {
31 const files = await this.vscfs.readDirectory(dir);
32 return files.filter((f) => f[1] === vscode.FileType.File).map((f) => vscode.Uri.file(f[0]));
33 }
34
35 // URI-based filesystem functions
36
37 async copy(source: vscode.Uri, destination: vscode.Uri, options?: { overwrite: boolean }): Promise<void> {
38 await this.vscfs.copy(source, destination, options);
39 }
40
41 async createDirectory(uri: vscode.Uri): Promise<void> {
42 await this.vscfs.createDirectory(uri);
43 }
44
45 async delete(uri: vscode.Uri): Promise<void> {
46 await this.vscfs.delete(uri);
47 }
48
49 async readFile(uri: vscode.Uri): Promise<string> {
50 const result = await this.vscfs.readFile(uri);
51 return new TextDecoder().decode(result);
52 }
53
54 async stat(uri: vscode.Uri): Promise<vscode.FileStat> {
55 return this.vscfs.stat(uri);
56 }
57
58 async writeFile(uri: vscode.Uri, text: string | Uint8Array): Promise<void> {
59 return this.vscfs.writeFile(uri, typeof text === 'string' ? new TextEncoder().encode(text) : text);
60 }
61
62 async exists(
63 // the "file" to look for
64 filename: vscode.Uri,
65 // the file type to expect; if not provided then any file type
66 // matches; otherwise a mismatch results in a "false" value
67 fileType?: vscode.FileType
68 ): Promise<boolean> {
69 // Special case. http/https always returns stat true even if the file doesn't
70 // exist. In those two cases use the http client instead
71 if (filename.scheme.toLowerCase() === 'http' || filename.scheme.toLowerCase() === 'https') {
72 return new HttpClient().exists(filename.toString());
73 }
74
75 // Otherwise use stat
76 let stat: vscode.FileStat;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected