import * as fs from 'fs' ; import fileSize from 'filesize' ; export function copyFile ( source , target , cb ) { var cbCalled = false ; var rd = fs . createReadStream ( source ) ; rd . on ( 'error' , function ( err ) { done ( err ) ; } ) ; var wr = fs . createWriteStream ( target ) ; wr . on ( 'error' , function ( err ) { done ( err ) ; } ) ; wr . on ( 'close' , function ( ex ) { done ( ) ; } ) ; rd . pipe ( wr ) ; function done ( err ? ) { if ( ! cbCalled ) { cb ( err ) ; cbCalled = true ; } } } export function getFilesize ( source ) { return new Promise ( ( resolve , reject ) => { fs . stat ( source , ( err , info ) => { if ( err ) { return reject ( err ) ; } return resolve ( fileSize ( info . size ) ) ; } ) ; } ) ; } export function isLocalFile ( source ) { return source . indexOf ( '://' ) == - 1 ; } export function isUrlEncodedFile ( path ) { return path . startsWith ( 'data:image' ) ; }