import fs from "fs" ; export class Disk { constructor ( ) { } public exists ( path ) { return new Promise < boolean > ( ( resolve ) => { fs . access ( path , fs . constants . F_OK | fs . constants . R_OK | fs . constants . W_OK , ( ( err ) => { err ? resolve ( false ) : resolve ( true ) ; } ) ) ; } ) ; } public async createDirectory ( path , recursive ) { return new Promise < boolean > ( ( resolve ) => { fs . mkdir ( path , { recursive : recursive } , ( ( err ) => { err ? resolve ( false ) : resolve ( true ) ; } ) ) ; } ) ; } public async save ( path , text ) { return new Promise < boolean > ( ( resolve ) => { fs . writeFile ( path , text , { encoding : "utf8" } , ( ( err ) => { err ? resolve ( false ) : resolve ( true ) ; } ) ) ; } ) ; } public async load ( path ) { return new Promise < string > ( ( resolve , reject ) => { fs . readFile ( path , { encoding : "utf8" } , ( ( err , text ) => { err ? reject ( err . message ) : resolve ( text ) ; } ) ) ; } ) ; } public async remove ( path ) { return new Promise < boolean > ( ( resolve ) => { fs . rm ( path , ( ( err ) => { err ? resolve ( false ) : resolve ( true ) ; } ) ) ; } ) ; } }