@@ -62,17 +62,22 @@ export interface IFileSystemReadFolderOptions {
6262}
6363
6464/**
65- * The options for {@link FileSystem.writeBuffersToFile}
6665 * @public
6766 */
68- export interface IFileSystemWriteBinaryFileOptions {
67+ export interface IFileSystemWriteFileOptionsBase {
6968 /**
7069 * If true, will ensure the folder is created before writing the file.
7170 * @defaultValue false
7271 */
7372 ensureFolderExists ?: boolean ;
7473}
7574
75+ /**
76+ * The options for {@link FileSystem.writeBuffersToFile}
77+ * @public
78+ */
79+ export interface IFileSystemWriteBinaryFileOptions extends IFileSystemWriteFileOptionsBase { }
80+
7681/**
7782 * The options for {@link FileSystem.writeFile}
7883 * @public
@@ -113,7 +118,7 @@ export interface IFileSystemReadFileOptions {
113118 * The options for {@link FileSystem.move}
114119 * @public
115120 */
116- export interface IFileSystemMoveOptions {
121+ export interface IFileSystemMoveOptions extends IFileSystemWriteFileOptionsBase {
117122 /**
118123 * The path of the existing object to be moved.
119124 * The path may be absolute or relative.
@@ -131,12 +136,6 @@ export interface IFileSystemMoveOptions {
131136 * @defaultValue true
132137 */
133138 overwrite ?: boolean ;
134-
135- /**
136- * If true, will ensure the folder is created before writing the file.
137- * @defaultValue false
138- */
139- ensureFolderExists ?: boolean ;
140139}
141140
142141/**
@@ -280,13 +279,7 @@ export interface IFileSystemCopyFilesOptions extends IFileSystemCopyFilesAsyncOp
280279 * The options for {@link FileSystem.createWriteStream}
281280 * @public
282281 */
283- export interface IFileSystemCreateWriteStreamOptions {
284- /**
285- * If true, will ensure the folder is created before writing the file.
286- * @defaultValue false
287- */
288- ensureFolderExists ?: boolean ;
289- }
282+ export interface IFileSystemCreateWriteStreamOptions extends IFileSystemWriteFileOptionsBase { }
290283
291284/**
292285 * The options for {@link FileSystem.deleteFile}
@@ -780,10 +773,11 @@ export class FileSystem {
780773 * Writes a text string to a file on disk, overwriting the file if it already exists.
781774 * Behind the scenes it uses `fs.writeFileSync()`.
782775 * @remarks
783- * Throws an error if the folder doesn't exist, unless ensureFolder=true.
776+ * Throws an error if the folder doesn't exist, unless {@link IFileSystemWriteFileOptionsBase.ensureFolderExists}
777+ * is set to `true`.
784778 * @param filePath - The absolute or relative path of the file.
785779 * @param contents - The text that should be written to the file.
786- * @param options - Optional settings that can change the behavior. Type: `IWriteFileOptions`
780+ * @param options - Optional settings that can change the behavior.
787781 */
788782 public static writeFile (
789783 filePath : string ,
@@ -826,7 +820,8 @@ export class FileSystem {
826820 * multiple sources.
827821 *
828822 * @remarks
829- * Throws an error if the folder doesn't exist, unless ensureFolder=true.
823+ * Throws an error if the folder doesn't exist, unless {@link IFileSystemWriteFileOptionsBase.ensureFolderExists}
824+ * is set to `true`.
830825 * @param filePath - The absolute or relative path of the file.
831826 * @param contents - The content that should be written to the file.
832827 * @param options - Optional settings that can change the behavior.
@@ -986,10 +981,11 @@ export class FileSystem {
986981 * Writes a text string to a file on disk, appending to the file if it already exists.
987982 * Behind the scenes it uses `fs.appendFileSync()`.
988983 * @remarks
989- * Throws an error if the folder doesn't exist, unless ensureFolder=true.
984+ * Throws an error if the folder doesn't exist, unless {@link IFileSystemWriteFileOptionsBase.ensureFolderExists}
985+ * is set to `true`.
990986 * @param filePath - The absolute or relative path of the file.
991987 * @param contents - The text that should be written to the file.
992- * @param options - Optional settings that can change the behavior. Type: `IWriteFileOptions`
988+ * @param options - Optional settings that can change the behavior.
993989 */
994990 public static appendToFile (
995991 filePath : string ,
@@ -1283,7 +1279,7 @@ export class FileSystem {
12831279 * Behind the scenes it uses `fs.createWriteStream()`.
12841280 *
12851281 * @remarks
1286- * Throws an error if the folder doesn't exist, unless {@link IFileSystemCreateWriteStreamOptions .ensureFolderExists}
1282+ * Throws an error if the folder doesn't exist, unless {@link IFileSystemWriteFileOptionsBase .ensureFolderExists}
12871283 * is set to `true`.
12881284 * @param filePath - The path to the file. The path may be absolute or relative.
12891285 * @param options - Optional settings that can change the behavior.
@@ -1297,6 +1293,22 @@ export class FileSystem {
12971293 const folderPath : string = nodeJsPath . dirname ( filePath ) ;
12981294 FileSystem . ensureFolder ( folderPath ) ;
12991295 }
1296+
1297+ return fs . createWriteStream ( filePath ) ;
1298+ }
1299+
1300+ /**
1301+ * An async version of {@link FileSystem.createWriteStream}.
1302+ */
1303+ public static async createWriteStreamAsync (
1304+ filePath : string ,
1305+ options ?: IFileSystemCreateWriteStreamOptions
1306+ ) : Promise < FileSystemWriteStream > {
1307+ if ( options ?. ensureFolderExists ) {
1308+ const folderPath : string = nodeJsPath . dirname ( filePath ) ;
1309+ await FileSystem . ensureFolderAsync ( folderPath ) ;
1310+ }
1311+
13001312 return fs . createWriteStream ( filePath ) ;
13011313 }
13021314
0 commit comments