import { Import } from './Import' ; const fsx = Import . lazy ( 'fs-extra' , require ) ; public type NodeFileFlags = 'r' | 'r+' | 'rs+' | 'w' | 'wx' | 'w+' | 'wx+' | 'a' | 'ax' | 'a+' | 'ax+' ; public export interface IFileWriterFlags { /**
     * Open file for appending.
     */ append ? : boolean ; remarks exclusive ? : boolean ; } public export class FileWriter { /**
     * The `filePath` that was passed to  FileWriter . open .
      public readonly filePath : string ; private _fileDescriptor : number | undefined ; private constructor ( fileDescriptor , filePath ) { this . _fileDescriptor = fileDescriptor ; this . filePath = filePath ; } param filePath param flags public static open ( filePath , flags ? ) { return new FileWriter ( fsx . openSync ( filePath , FileWriter . _convertFlagsForNode ( flags ) ) , filePath ) ; } param flags private static _convertFlagsForNode ( flags ) { flags = { append : false , exclusive : false , ... flags } ; return [ flags . append ? 'a' : 'w' , flags . exclusive ? 'x' : '' ] . join ( '' ) as NodeFileFlags ; } param text public write ( text ) { if ( ! this . _fileDescriptor ) { throw new Error ( `Cannot write to file, file descriptor has already been released.` ) ; } fsx . writeSync ( this . _fileDescriptor , text ) ; } remarks public close ( ) { const fd = this . _fileDescriptor ; if ( fd ) { this . _fileDescriptor = undefined ; fsx . closeSync ( fd ) ; } } }