Skip to content

Commit ef8b3ba

Browse files
Fix downloader message
1 parent 4280ba5 commit ef8b3ba

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

install.js

+21-14
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const isGzUrl = (url) => {
8080
}
8181

8282
const noop = () => {}
83+
8384
function downloadFile(url, destinationPath, progressCallback = noop) {
8485
let fulfill, reject;
8586
let totalBytes = 0;
@@ -135,19 +136,25 @@ function downloadFile(url, destinationPath, progressCallback = noop) {
135136
return promise;
136137
}
137138

138-
let progressBar = null;
139-
function onProgress(deltaBytes, totalBytes) {
140-
if (totalBytes === null) return;
141-
if (!progressBar) {
142-
progressBar = new ProgressBar(`Downloading ffmpeg ${releaseName} [:bar] :percent :etas `, {
143-
complete: "|",
144-
incomplete: " ",
145-
width: 20,
146-
total: totalBytes
147-
});
148-
}
149139

150-
progressBar.tick(deltaBytes);
140+
function getProgressIndicator(tool) {
141+
let progressBar = null;
142+
143+
return (deltaBytes,totalBytes) => {
144+
if (progressBar == null) {
145+
progressBar = new ProgressBar(`Downloading ${tool} ${releaseName} [:bar] :percent :etas `, {
146+
complete: "|",
147+
incomplete: " ",
148+
width: 20,
149+
total: totalBytes,
150+
});
151+
152+
}
153+
if(progressBar.total !== totalBytes) {
154+
progressBar.total = totalBytes;
155+
}
156+
progressBar.tick(deltaBytes);
157+
}
151158
}
152159

153160
const release = (
@@ -169,13 +176,13 @@ const ffprobeUrl = `${baseUrl}/ffprobe-${platform}-${arch}`
169176
const readmeUrl = `${baseUrl}/${platform}-${arch}.README`
170177
const licenseUrl = `${baseUrl}/${platform}-${arch}.LICENSE`
171178

172-
downloadFile(ffmpegUrl, ffmpegPath, onProgress)
179+
downloadFile(ffmpegUrl, ffmpegPath, getProgressIndicator('ffmpeg'))
173180
.then(() => {
174181
fs.chmodSync(ffmpegPath, 0o755) // make executable
175182
})
176183
.catch(exitOnError)
177184

178-
.then(() => downloadFile(ffprobeUrl, ffprobePath, onProgress))
185+
.then(() => downloadFile(ffprobeUrl, ffprobePath, getProgressIndicator('ffprobe')))
179186
.then(() => {
180187
fs.chmodSync(ffprobePath, 0o755) // make executable
181188
})

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)