UNPKG

angular-ide

Version:

Provides a seamless integration with the Angular IDE from the command-line for developers looking for an enhanced development experience with Angular.

70 lines (54 loc) 1.98 kB
const DecompressZip = require('decompress-zip'); const Rx = require('rxjs'); const fs = require('fs'); const zlib = require('zlib'); const tar = require('tar-fs'); const fStat = Rx.Observable.bindNodeCallback(fs.stat); function zip(compressedFilePath$, destinationPath$) { return Rx.Observable.create((observer) => { compressedFilePath$.withLatestFrom(destinationPath$) .subscribe(([compressedFilePath, destinationPath]) => { const unzipper = new DecompressZip(compressedFilePath); unzipper.on('progress', (index, count) => { observer.next({ current: index, total: count }); }); unzipper.on('extract', () => { observer.complete(); }); unzipper.extract({ path: destinationPath }); }); }).share(); }; function tarGZ(compressedFilePath$, destinationPath$) { return Rx.Observable.create((observer) => { compressedFilePath$.combineLatest(destinationPath$) .subscribe(([compressedFilePath, destinationPath]) => { const gunzip = zlib.createGunzip(); fStat(compressedFilePath) .subscribe(fileStats => { const fileSize = fileStats.size; const inp = fs.createReadStream(compressedFilePath); const tarExtract = tar.extract(destinationPath); tarExtract.on('finish', function() { observer.complete(); }); inp.pipe(gunzip).pipe(tarExtract); let readTotal = 0; inp.on('data', (data) => { readTotal += data.length; observer.next({ current: readTotal, total: fileSize, }); }); }); }); }).share(); } module.exports = function extract(compressedFilePath$, destinationPath$, osType){ if (osType === 'Windows_NT') { return zip(compressedFilePath$, destinationPath$); } else { return tarGZ(compressedFilePath$, destinationPath$); } };