import * as vscode from 'vscode' ; import * as fs from 'fs' ; function handleResult < T > ( resolve , reject , error , result ) { if ( error ) { reject ( massageError ( error ) ) ; } else { resolve ( result ) ; } } function massageError ( error ) { if ( error . code === 'ENOENT' ) { return vscode . FileSystemError . FileNotFound ( ) ; } if ( error . code === 'EISDIR' ) { return vscode . FileSystemError . FileIsADirectory ( ) ; } if ( error . code === 'EEXIST' ) { return vscode . FileSystemError . FileExists ( ) ; } if ( error . code === 'EPERM' || error . code === 'EACCESS' ) { return vscode . FileSystemError . NoPermissions ( ) ; } return error ; } export function readFile ( path ) { return new Promise < Buffer > ( ( resolve , reject ) => { fs . readFile ( path , ( error , buffer ) => handleResult ( resolve , reject , error , buffer ) ) ; } ) ; } export function writeFile ( path , content ) { return new Promise < void > ( ( resolve , reject ) => { fs . writeFile ( path , content , error => handleResult ( resolve , reject , error , void 0 ) ) ; } ) ; } export function exists ( path ) { return new Promise < boolean > ( ( resolve , reject ) => { fs . exists ( path , exists => handleResult ( resolve , reject , null , exists ) ) ; } ) ; } export function readdir ( path ) { return new Promise < string [ ] > ( ( resolve , reject ) => { fs . readdir ( path , ( error , files ) => handleResult ( resolve , reject , error , files ) ) ; } ) ; } export function unlink ( path ) { return new Promise < void > ( ( resolve , reject ) => { fs . unlink ( path , error => handleResult ( resolve , reject , error , void 0 ) ) ; } ) ; }