Skip to content

Commit 3147e27

Browse files
authored
Replace broken unzipper with extract-zip. (#3338)
Fixes #3335
1 parent 8c31f21 commit 3147e27

File tree

3 files changed

+184
-352
lines changed

3 files changed

+184
-352
lines changed

src/Azure.Functions.Cli/npm/lib/install.js

+35-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /usr/bin/env node
22

3-
const unzipper = require('unzipper');
3+
const extract = require('extract-zip');
44
const url = require('url');
55
const HttpsProxyAgent = require('https-proxy-agent');
66
const https = require('https');
@@ -40,7 +40,8 @@ if (os.platform() === 'win32') {
4040
throw Error('platform ' + os.platform() + ' isn\'t supported');
4141
}
4242

43-
const endpoint = 'https://functionscdn.azureedge.net/public/' + version + '/Azure.Functions.Cli.' + platform + '.' + version + '.zip';
43+
const fileName = 'Azure.Functions.Cli.' + platform + '.' + version + '.zip';
44+
const endpoint = 'https://functionscdn.azureedge.net/public/' + version + '/' + fileName;
4445
console.log('attempting to GET %j', endpoint);
4546
const options = url.parse(endpoint);
4647
// npm config preceed system environment
@@ -67,20 +68,29 @@ if (proxy) {
6768
}
6869

6970
https.get(options, response => {
71+
const bar = new ProgressBar('[:bar] Downloading Azure Functions Core Tools', {
72+
total: Number(response.headers['content-length']),
73+
width: 18
74+
});
7075

71-
const bar = new ProgressBar('[:bar] Downloading Azure Functions Core Tools', {
72-
total: Number(response.headers['content-length']),
73-
width: 18
74-
});
75-
76-
if (response.statusCode === 200) {
77-
const installPath = getPath();
78-
response.on('data', data => bar.tick(data.length));
79-
const unzipStream = unzipper.Extract({ path: installPath })
80-
.on('close', () => {
76+
if (response.statusCode === 200) {
77+
const installPath = getPath();
78+
const downloadPath = installPath + '/' + fileName;
79+
response.on('data', data => bar.tick(data.length));
80+
if (!fs.existsSync(installPath)) {
81+
fs.mkdirSync(installPath);
82+
}
83+
const file = fs.createWriteStream(downloadPath);
84+
response.pipe(file);
85+
file.on('finish', function() {
86+
file.close(() => {
87+
extract(file.path, {
88+
dir: installPath
89+
}).then(() => {
8190
try {
82-
fs.closeSync(fs.openSync(`${installPath}/telemetryDefaultOn.sentinel`, 'w'))
83-
console.log(telemetryInfo)
91+
fs.closeSync(fs.openSync(`${installPath}/telemetryDefaultOn.sentinel`, 'w'));
92+
console.log(telemetryInfo);
93+
fs.unlinkSync(downloadPath);
8494
}
8595
catch (err) {
8696
// That's alright.
@@ -90,14 +100,15 @@ https.get(options, response => {
90100
fs.chmodSync(`${installPath}/gozip`, 0o755);
91101
}
92102
});
93-
response.pipe(unzipStream);
94-
} else {
95-
console.error(chalk.red('Error downloading zip file from ' + endpoint));
96-
console.error(chalk.red('Expected: 200, Actual: ' + response.statusCode));
97-
process.exit(1);
98-
}
99-
})
100-
.on('error', err => {
101-
console.error(chalk.red(err));
103+
});
104+
});
105+
} else {
106+
console.error(chalk.red('Error downloading zip file from ' + endpoint));
107+
console.error(chalk.red('Expected: 200, Actual: ' + response.statusCode));
102108
process.exit(1);
103-
});
109+
}
110+
})
111+
.on('error', err => {
112+
console.error(chalk.red(err));
113+
process.exit(1);
114+
});

0 commit comments

Comments
 (0)