import * as fs from "fs" ; export class FileUtil { public static copyFile ( source , target , callback ? ) { let cbCalled = false ; let readStream = fs . createReadStream ( source ) ; readStream . on ( "error" , function ( error ) { done ( error ) ; } ) ; let writeStream = fs . createWriteStream ( target ) ; writeStream . on ( "error" , function ( error ) { done ( error ) ; } ) ; writeStream . on ( "close" , function ( ) { done ( ) ; } ) ; readStream . pipe ( writeStream ) ; function done ( error ? ) { if ( ! cbCalled ) { if ( callback !== undefined && callback !== null ) { callback ( error ) ; } cbCalled = true ; } } } public static readFile ( source , callback ) { fs . readFile ( source , null , function ( error , data ) { if ( error !== null ) { callback ( null ) ; } else { callback ( data ) ; } } ) ; } }