From df72cac5bffe59667a3aa129bba002c76a819d06 Mon Sep 17 00:00:00 2001 From: Mikhail Arkhipov Date: Tue, 17 Apr 2018 13:22:58 -0700 Subject: [PATCH] Replace unzip package (#1419) * Undo changes * Test fixes * Increase timeout * Remove double event listening * Remove test * Revert "Remove test" This reverts commit e240c3fd117c38b9e6fdcbdd1ba2715789fefe48. * Revert "Remove double event listening" This reverts commit af573be27372a79d5589e2134002cc753bb54f2a. * #1096 The if statement is automatically formatted incorrectly * Merge fix * Add more tests * More tests * Typo * Test * Also better handle multiline arguments * Add a couple missing periods [skip ci] * Undo changes * Test fixes * Increase timeout * Remove double event listening * Remove test * Revert "Remove test" This reverts commit e240c3fd117c38b9e6fdcbdd1ba2715789fefe48. * Revert "Remove double event listening" This reverts commit af573be27372a79d5589e2134002cc753bb54f2a. * Merge fix * #1257 On type formatting errors for args and kwargs * Handle f-strings * Stop importing from test code * #1308 Single line statements leading to an indentation on the next line * #726 editing python after inline if statement invalid indent * Undo change * Move constant * Harden LS startup error checks * #1364 Intellisense doesn't work after specific const string * Telemetry for the analysis enging * PR feedback * Fix typo * Test baseline update * Jedi 0.12 * Priority to goto_defition * News * Replace unzip --- package.json | 2 +- src/client/activation/downloader.ts | 42 ++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 434dc231a1d8..74853cf944cd 100644 --- a/package.json +++ b/package.json @@ -1848,6 +1848,7 @@ "md5": "2.2.1", "minimatch": "3.0.4", "named-js-regexp": "1.3.3", + "node-stream-zip": "^1.6.0", "opn": "5.3.0", "pidusage": "1.2.0", "reflect-metadata": "0.1.12", @@ -1862,7 +1863,6 @@ "uint64be": "1.0.1", "unicode": "10.0.0", "untildify": "3.0.2", - "unzip": "0.1.11", "vscode-debugadapter": "1.28.0", "vscode-debugprotocol": "1.28.0", "vscode-extension-telemetry": "0.0.15", diff --git a/src/client/activation/downloader.ts b/src/client/activation/downloader.ts index de634d627316..c48b0b4b2503 100644 --- a/src/client/activation/downloader.ts +++ b/src/client/activation/downloader.ts @@ -5,7 +5,6 @@ import * as fs from 'fs'; import * as path from 'path'; import * as request from 'request'; import * as requestProgress from 'request-progress'; -import * as unzip from 'unzip'; import { ExtensionContext, OutputChannel, ProgressLocation, window } from 'vscode'; import { STANDARD_OUTPUT_CHANNEL } from '../common/constants'; import { noop } from '../common/core.utils'; @@ -16,6 +15,9 @@ import { IServiceContainer } from '../ioc/types'; import { HashVerifier } from './hashVerifier'; import { PlatformData } from './platformData'; +// tslint:disable-next-line:no-require-imports no-var-requires +const StreamZip = require('node-stream-zip'); + const downloadUriPrefix = 'https://pvsc.blob.core.windows.net/python-analysis'; const downloadBaseFileName = 'python-analysis-vscode'; const downloadVersion = '0.1.0'; @@ -109,15 +111,37 @@ export class AnalysisEngineDownloader { const installFolder = path.join(extensionPath, this.engineFolder); const deferred = createDeferred(); - fs.createReadStream(tempFilePath) - .pipe(unzip.Extract({ path: installFolder })) - .on('finish', () => { - deferred.resolve(); - }) - .on('error', (err) => { - deferred.reject(err); + const title = 'Extracting files... '; + await window.withProgress({ + location: ProgressLocation.Window, + title + }, (progress) => { + const zip = new StreamZip({ + file: tempFilePath, + storeEntries: true }); - await deferred.promise; + + let totalFiles = 0; + let extractedFiles = 0; + zip.on('ready', () => { + totalFiles = zip.entriesCount; + if (!fs.existsSync(installFolder)) { + fs.mkdirSync(installFolder); + } + zip.extract(null, installFolder, (err, count) => { + if (err) { + deferred.reject(err); + } else { + deferred.resolve(); + } + zip.close(); + }); + }).on('extract', (entry, file) => { + extractedFiles += 1; + progress.report({ message: `${title}${Math.round(100 * extractedFiles / totalFiles)}%` }); + }); + return deferred.promise; + }); this.output.append('done.'); // Set file to executable