import fs from 'fs' ; import { PortablePath } from '@boost/common' ; import { FileTransport } from '../../src/transports/FileTransport' ; export function existsFile ( path ) { return fs . existsSync ( String ( path ) ) ; } export function readFile ( path ) { if ( existsFile ( path ) ) { return fs . readFileSync ( String ( path ) , 'utf8' ) ; } return '' ; } export function writeFile ( path , content ) { fs . writeFileSync ( String ( path ) , content , 'utf8' ) ; } export function sizeFile ( path ) { return fs . statSync ( String ( path ) ) . size ; } export async function wait ( delay ) { return new Promise ( ( resolve ) => { setTimeout ( resolve , delay ) ; } ) ; } export async function closeStream ( transport ) { await wait ( 0 ) ; return new Promise ( ( resolve , reject ) => { if ( transport . stream ) { transport . stream . on ( 'error' , reject ) ; transport . close ( ( ) => { resolve ( undefined ) ; } ) ; } else { resolve ( undefined ) ; } } ) ; }