Skip to content

Commit 8da70ce

Browse files
committed
fixup! Add createReadStream/createWriteStream to FileSystem in node-core-library and update consumers to use FileSystem instead of fs directly
Wrap FileSystem stream methods in _wrapException for consistent error handling
1 parent c774a67 commit 8da70ce

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

libraries/node-core-library/src/FileSystem.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,9 @@ export class FileSystem {
12711271
* @returns A new readable stream for the file.
12721272
*/
12731273
public static createReadStream(filePath: string): FileSystemReadStream {
1274-
return fs.createReadStream(filePath);
1274+
return FileSystem._wrapException(() => {
1275+
return fs.createReadStream(filePath);
1276+
});
12751277
}
12761278

12771279
/**
@@ -1289,12 +1291,14 @@ export class FileSystem {
12891291
filePath: string,
12901292
options?: IFileSystemCreateWriteStreamOptions
12911293
): FileSystemWriteStream {
1292-
if (options?.ensureFolderExists) {
1293-
const folderPath: string = nodeJsPath.dirname(filePath);
1294-
FileSystem.ensureFolder(folderPath);
1295-
}
1294+
return FileSystem._wrapException(() => {
1295+
if (options?.ensureFolderExists) {
1296+
const folderPath: string = nodeJsPath.dirname(filePath);
1297+
FileSystem.ensureFolder(folderPath);
1298+
}
12961299

1297-
return fs.createWriteStream(filePath);
1300+
return fs.createWriteStream(filePath);
1301+
});
12981302
}
12991303

13001304
/**
@@ -1304,12 +1308,14 @@ export class FileSystem {
13041308
filePath: string,
13051309
options?: IFileSystemCreateWriteStreamOptions
13061310
): Promise<FileSystemWriteStream> {
1307-
if (options?.ensureFolderExists) {
1308-
const folderPath: string = nodeJsPath.dirname(filePath);
1309-
await FileSystem.ensureFolderAsync(folderPath);
1310-
}
1311+
return await FileSystem._wrapExceptionAsync(async () => {
1312+
if (options?.ensureFolderExists) {
1313+
const folderPath: string = nodeJsPath.dirname(filePath);
1314+
await FileSystem.ensureFolderAsync(folderPath);
1315+
}
13111316

1312-
return fs.createWriteStream(filePath);
1317+
return fs.createWriteStream(filePath);
1318+
});
13131319
}
13141320

13151321
// ===============

0 commit comments

Comments
 (0)