import { create } from 'tar' ; import { createConnection } from 'net' ; export function uploadToServer ( dir , host , port ) { return new Promise < string > ( ( resolve , reject ) => { const stream = create ( { gzip : true , portable : true } , [ dir ] ) ; const socket = createConnection ( { host , port } ) ; stream . on ( 'data' , ( data ) => { console . log ( 'data' ) ; socket . write ( data ) ; } ) ; stream . on ( 'end' , ( ) => { console . log ( 'end' ) ; socket . end ( ) ; } ) ; socket . on ( 'close' , ( ) => { console . log ( 'close' ) ; resolve ( dir ) ; } ) ; socket . on ( 'error' , ( err ) => { reject ( err ) ; } ) ; } ) ; }