import { error , info , warn } from 'electron-log' ; import { createReadStream , createWriteStream , pathExists } from 'fs-extra' ; import { join } from 'path' ; import archiver from 'archiver' ; import unzipper from 'unzipper' ; param filePath param destination export const unzip = ( args ) : Promise < any > => new Promise ( async ( resolve , reject ) => { const { filePath , destination } = args ; const exists = await pathExists ( filePath ) ; if ( ! exists ) { throw Error ( `${ filePath } does not exist!` ) ; } const stream = createReadStream ( filePath ) . pipe ( unzipper . Extract ( { path : destination } ) ) ; stream . on ( 'close' , resolve ) ; stream . on ( 'error' , err => { error ( `Could not unzip ${ filePath } into ${ destination }:` , err ) ; reject ( err ) ; } ) ; } ) ; param source param destination export const zip = ( args ) : Promise < void > => new Promise ( async ( resolve , reject ) => { const { source , destination } = args ; info ( `zipping ${ source } to ${ destination }` ) ; const archive = archiver ( 'zip' ) ; archive . on ( 'finish' , ( ) => resolve ( ) ) ; archive . on ( 'error' , err => { error ( `got error when zipping ${ destination }:` , err ) ; reject ( err ) ; } ) ; archive . on ( 'warning' , warning => { warn ( `got warning when zipping ${ destination }:` , warning ) ; reject ( warning ) ; } ) ; archive . pipe ( createWriteStream ( destination ) ) ; const entryData = entry => { const rpcPath = join ( 'lightningd' , 'regtest' , 'lightning-rpc' ) ; if ( entry . name && entry . name . endsWith ( rpcPath ) ) { info ( 'skipping' , entry ) ; return false ; } return entry ; } ; archive . directory ( source , false , entryData ) ; archive . finalize ( ) ; } ) ;