Skip to content

Commit a6da8d3

Browse files
Factor out RawFileSystem. (#9499)
(for #8995) This separates the low-level filesystem operations from the high-level "fs utils". The move to the VS Code FS API can then happen strictly inside RawFileSystem. Also, this is part of what we reverted in #8970. Note that the bulk of the changes are in test code. Also, of the non-test code, the changes are either just moving things around (from FileSystem to RawFileSystem), or adding the new RawFileSystem class (and IRawFileSystem interface).
1 parent 4cf1e5c commit a6da8d3

9 files changed

+2160
-885
lines changed

src/client/common/platform/fileSystem.ts

Lines changed: 324 additions & 162 deletions
Large diffs are not rendered by default.

src/client/common/platform/types.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,57 @@ export interface IFileSystemPathUtils {
9191

9292
export import FileType = vscode.FileType;
9393
export import FileStat = vscode.FileStat;
94+
export type ReadStream = fs.ReadStream;
9495
export type WriteStream = fs.WriteStream;
9596

97+
// The low-level filesystem operations on which the extension depends.
98+
export interface IRawFileSystem {
99+
// Get information about a file (resolve symlinks).
100+
stat(filename: string): Promise<FileStat>;
101+
// Get information about a file (do not resolve synlinks).
102+
lstat(filename: string): Promise<FileStat>;
103+
// Change a file's permissions.
104+
chmod(filename: string, mode: string | number): Promise<void>;
105+
// Move the file to a different location (and/or rename it).
106+
move(src: string, tgt: string): Promise<void>;
107+
108+
//***********************
109+
// files
110+
111+
// Return the raw bytes of the given file.
112+
readData(filename: string): Promise<Buffer>;
113+
// Return the text of the given file (decoded from UTF-8).
114+
readText(filename: string): Promise<string>;
115+
// Write the given text to the file (UTF-8 encoded).
116+
writeText(filename: string, data: {}): Promise<void>;
117+
// Write the given text to the end of the file (UTF-8 encoded).
118+
appendText(filename: string, text: string): Promise<void>;
119+
// Copy a file.
120+
copyFile(src: string, dest: string): Promise<void>;
121+
// Delete a file.
122+
rmfile(filename: string): Promise<void>;
123+
124+
//***********************
125+
// directories
126+
127+
// Create the directory and any missing parent directories.
128+
mkdirp(dirname: string): Promise<void>;
129+
// Delete the directory and everything in it.
130+
rmtree(dirname: string): Promise<void>;
131+
// Return the contents of the directory.
132+
listdir(dirname: string): Promise<[string, FileType][]>;
133+
134+
//***********************
135+
// not async
136+
137+
// Return the text of the given file (decoded from UTF-8).
138+
readTextSync(filename: string): string;
139+
// Create a streaming wrappr around an open file (for reading).
140+
createReadStream(filename: string): ReadStream;
141+
// Create a streaming wrappr around an open file (for writing).
142+
createWriteStream(filename: string): WriteStream;
143+
}
144+
96145
export const IFileSystem = Symbol('IFileSystem');
97146
export interface IFileSystem {
98147
// path-related
@@ -106,8 +155,8 @@ export interface IFileSystem {
106155
listdir(dirname: string): Promise<[string, FileType][]>;
107156
readFile(filePath: string): Promise<string>;
108157
readData(filePath: string): Promise<Buffer>;
109-
writeFile(filePath: string, data: {}, options?: string | fsextra.WriteFileOptions): Promise<void>;
110-
appendFile(filename: string, data: {}): Promise<void>;
158+
writeFile(filePath: string, text: string | Buffer, options?: string | fsextra.WriteFileOptions): Promise<void>;
159+
appendFile(filename: string, text: string | Buffer): Promise<void>;
111160
copyFile(src: string, dest: string): Promise<void>;
112161
deleteFile(filename: string): Promise<void>;
113162
chmod(path: string, mode: string | number): Promise<void>;

0 commit comments

Comments
 (0)