import * as sysfs from 'fs' ; import { promisify } from 'util' ; export interface FS { chmod ( path , mode ) : Promise < void > ; existsSync ( path ) : boolean ; readFile ( filename , encoding , callback ) : void ; readTextFile ( path ) : Promise < string > ; readFileAsync ( filename ) : Promise < Buffer > ; renameAsync ( oldName , newName ) : Promise < void > ; readFileSync ( filename , encoding ) : string ; readFileToBufferSync ( filename ) : Buffer ; writeFile ( filename , data , callback ) : void ; writeTextFile ( filename , text ) : Promise < void > ; writeFileSync ( filename , data ) : void ; dirSync ( path ) : string [ ] ; unlinkAsync ( path ) : Promise < void > ; existsAsync ( path ) : Promise < boolean > ; openAsync ( path , flags ) : Promise < void > ; statSync ( path ) : sysfs . Stats ; } export const fs = { chmod : promisify ( ( path , mode , cb ) => sysfs . chmod ( path , mode , cb ) ) , existsSync : ( path ) => sysfs . existsSync ( path ) , readFile : ( filename , encoding , callback ) => sysfs . readFile ( filename , encoding , callback ) , readTextFile : promisify ( ( path , cb ) => sysfs . readFile ( path , { encoding : 'utf8' } , cb ) ) , readFileAsync : promisify ( ( path , cb ) => sysfs . readFile ( path , null , cb ) ) , readFileSync : ( filename , encoding ) => sysfs . readFileSync ( filename , encoding ) , readFileToBufferSync : ( filename ) => sysfs . readFileSync ( filename ) , renameAsync : promisify ( ( oldName , newName , cb ) => sysfs . rename ( oldName , newName , cb ) ) , writeFile : ( filename , data , callback ) => sysfs . writeFile ( filename , data , callback ) , writeTextFile : promisify ( ( filename , data , callback ) => sysfs . writeFile ( filename , data , callback ) ) , writeFileSync : ( filename , data ) => sysfs . writeFileSync ( filename , data ) , dirSync : ( path ) => sysfs . readdirSync ( path ) , unlinkAsync : ( path ) => { return new Promise ( ( resolve , reject ) => { sysfs . unlink ( path , ( error ) => { if ( error ) { reject ( ) ; return ; } resolve ( ) ; } ) ; } ) ; } , existsAsync : ( path ) => { return new Promise ( ( resolve ) => { sysfs . exists ( path , ( exists ) => { resolve ( exists ) ; } ) ; } ) ; } , openAsync : ( path , flags ) => { return new Promise ( ( resolve , reject ) => { sysfs . open ( path , flags , ( error , _fd ) => { if ( error ) { reject ( ) ; return ; } resolve ( ) ; } ) ; } ) ; } , statSync : ( path ) => sysfs . statSync ( path ) } ;