@@ -18,7 +18,7 @@ import { PosixModeBits } from './PosixModeBits';
1818export interface IFileSystemReadFolderOptions {
1919 /**
2020 * If true, returns the absolute paths of the files in the folder.
21- * Defaults to ` false`.
21+ * @defaultValue false
2222 */
2323 absolutePaths ?: boolean ;
2424}
@@ -36,13 +36,13 @@ export interface IFileSystemWriteFileOptions {
3636
3737 /**
3838 * If specified, will normalize line endings to the specified style of newline.
39- * @defaultValue undefined
39+ * @defaultValue ` undefined` which means no conversion will be performed
4040 */
4141 convertLineEndings ?: NewlineKind ;
4242
4343 /**
4444 * If specified, will change the encoding of the file that will be written.
45- * Defaults to ` "utf8"`.
45+ * @defaultValue "utf8"
4646 */
4747 encoding ?: Encoding ;
4848}
@@ -60,7 +60,7 @@ export interface IFileSystemReadFileOptions {
6060
6161 /**
6262 * If specified, will normalize line endings to the specified style of newline.
63- * @defaultValue undefined
63+ * @defaultValue ` undefined` which means no conversion will be performed
6464 */
6565 convertLineEndings ?: NewlineKind ;
6666}
@@ -370,7 +370,9 @@ export class FileSystem {
370370 FileSystem . ensureFolder ( folderPath ) ;
371371 }
372372
373- contents = FileSystem . _convertLineEndings ( contents . toString ( ) , options . convertLineEndings ) ;
373+ if ( options . convertLineEndings ) {
374+ contents = Text . convertTo ( contents . toString ( ) , options . convertLineEndings ) ;
375+ }
374376
375377 fsx . writeFileSync ( filePath , contents , { encoding : options . encoding } ) ;
376378 }
@@ -397,7 +399,9 @@ export class FileSystem {
397399 FileSystem . ensureFolder ( folderPath ) ;
398400 }
399401
400- contents = FileSystem . _convertLineEndings ( contents . toString ( ) , options . convertLineEndings ) ;
402+ if ( options . convertLineEndings ) {
403+ contents = Text . convertTo ( contents . toString ( ) , options . convertLineEndings ) ;
404+ }
401405
402406 fsx . appendFileSync ( filePath , contents , { encoding : options . encoding } ) ;
403407 }
@@ -415,8 +419,11 @@ export class FileSystem {
415419 ...options
416420 } ;
417421
418- const contents : string = FileSystem . readFileToBuffer ( filePath ) . toString ( options . encoding ) ;
419- return FileSystem . _convertLineEndings ( contents , options . convertLineEndings ) ;
422+ let contents : string = FileSystem . readFileToBuffer ( filePath ) . toString ( options . encoding ) ;
423+ if ( options . convertLineEndings ) {
424+ contents = Text . convertTo ( contents , options . convertLineEndings ) ;
425+ }
426+ return contents ;
420427 }
421428
422429 /**
@@ -514,22 +521,4 @@ export class FileSystem {
514521 public static getRealPath ( linkPath : string ) : string {
515522 return fsx . realpathSync ( linkPath ) ;
516523 }
517-
518- /**
519- * A helper function that converts line endings on a string.
520- * @param text - The text to be normalized.
521- * @param lineEndings - The style of line endings to use.
522- */
523- private static _convertLineEndings ( text : string , lineEndings : NewlineKind | undefined ) : string {
524- switch ( lineEndings ) {
525- case NewlineKind . CrLf :
526- return Text . convertToCrLf ( text ) ;
527- case NewlineKind . Lf :
528- return Text . convertToLf ( text ) ;
529- case NewlineKind . OsDefault :
530- return Text . convertToOsDefault ( text ) ;
531- default :
532- return text ;
533- }
534- }
535524}
0 commit comments