Skip to content

Commit

Permalink
chore: Replace extract-zip with yauzl-promise
Browse files Browse the repository at this point in the history
Since extract-zip is abandonware, remove it and just work with
yauzl directly.

Fixes microsoft#1510
  • Loading branch information
ABuffSeagull committed Mar 25, 2020
1 parent 4b1fa2f commit 8647257
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@
"license": "Apache-2.0",
"dependencies": {
"debug": "^4.1.0",
"extract-zip": "^1.6.6",
"https-proxy-agent": "^3.0.0",
"jpeg-js": "^0.3.6",
"pngjs": "^3.4.0",
"progress": "^2.0.3",
"proxy-from-env": "^1.1.0",
"rimraf": "^3.0.2",
"ws": "^6.1.0"
"ws": "^6.1.0",
"yauzl-promise": "^2.1.3"
},
"devDependencies": {
"@types/debug": "0.0.31",
"@types/extract-zip": "^1.6.2",
"@types/node": "^8.10.34",
"@types/node": "^10.17.17",
"@types/pngjs": "^3.4.0",
"@types/proxy-from-env": "^1.0.0",
"@types/rimraf": "^2.0.2",
"@types/ws": "^6.0.1",
"@types/yauzl-promise": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^2.6.1",
"@typescript-eslint/parser": "^2.6.1",
"colors": "^1.4.0",
Expand Down
37 changes: 29 additions & 8 deletions src/server/browserFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import * as extract from 'extract-zip';
import * as yauzl from 'yauzl-promise';
import * as fs from 'fs';
import * as os from 'os';
import * as util from 'util';
Expand All @@ -27,6 +27,8 @@ import * as URL from 'url';
import { assert } from '../helper';
import * as platform from '../platform';

const fsPromises = fs.promises;

const unlinkAsync = platform.promisify(fs.unlink.bind(fs));
const chmodAsync = platform.promisify(fs.chmod.bind(fs));
const existsAsync = (path: string): Promise<boolean> => new Promise(resolve => fs.stat(path, err => resolve(!err)));
Expand Down Expand Up @@ -205,13 +207,32 @@ function downloadFile(url: string, destinationPath: string, progressCallback: On
}
}

function extractZip(zipPath: string, folderPath: string): Promise<Error | null> {
return new Promise((fulfill, reject) => extract(zipPath, {dir: folderPath}, err => {
if (err)
reject(err);
else
fulfill();
}));
async function extractZip(zipPath: string, folderPath: string) {
const zipfile = await yauzl.open(zipPath);

const finishedPromises: Promise<any>[] = [];

await zipfile.walkEntries(async entry => {
if (entry.fileName.endsWith('/')) {
await fsPromises.mkdir(path.resolve(folderPath, entry.fileName), { recursive: true });
} else {
const filepath = path.resolve(folderPath, entry.fileName);
await fsPromises.mkdir(path.parse(filepath).dir, { recursive: true });

const stream = await zipfile.openReadStream(entry);

const finishedPromise= new Promise((resolve, reject) => {
stream.on('end', resolve);
stream.on('error', reject);
});
finishedPromises.push(finishedPromise);

stream.pipe(fs.createWriteStream(filepath));
}
});

await Promise.all(finishedPromises);
zipfile.close();
}

function httpRequest(url: string, method: string, response: (r: any) => void) {
Expand Down

0 comments on commit 8647257

Please sign in to comment.