From 25bac72ac5c0a7b89db08f7cabdaf3e0387bfaa2 Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Mon, 22 Jun 2020 16:03:35 -0700 Subject: [PATCH] Use `Open` instead of `Extract` to open zip files This allows opening zip files whose local headers are not correct. --- extensions/ql-vscode/src/databaseFetcher.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/extensions/ql-vscode/src/databaseFetcher.ts b/extensions/ql-vscode/src/databaseFetcher.ts index 45021d549..d856f2953 100644 --- a/extensions/ql-vscode/src/databaseFetcher.ts +++ b/extensions/ql-vscode/src/databaseFetcher.ts @@ -9,6 +9,7 @@ import { } from 'vscode'; import * as fs from 'fs-extra'; import * as path from 'path'; + import { DatabaseManager, DatabaseItem } from './databases'; import { ProgressCallback, @@ -261,19 +262,9 @@ function validateHttpsUrl(databaseUrl: string) { } async function readAndUnzip(databaseUrl: string, unzipPath: string) { - const unzipStream = unzipper.Extract({ - path: unzipPath, - }); - - await new Promise((resolve, reject) => { - // we already know this is a file scheme - const databaseFile = Uri.parse(databaseUrl).fsPath; - const stream = fs.createReadStream(databaseFile); - stream.on('error', reject); - unzipStream.on('error', reject); - unzipStream.on('close', resolve); - stream.pipe(unzipStream); - }); + const databaseFile = Uri.parse(databaseUrl).fsPath; + const directory = await unzipper.Open.file(databaseFile); + await directory.extract({ path: unzipPath }); } async function fetchAndUnzip( @@ -288,6 +279,7 @@ async function fetchAndUnzip( const unzipStream = unzipper.Extract({ path: unzipPath, }); + progressCallback?.({ maxStep: 3, message: 'Unzipping database',