@@ -80,6 +80,7 @@ const isGzUrl = (url) => {
80
80
}
81
81
82
82
const noop = ( ) => { }
83
+
83
84
function downloadFile ( url , destinationPath , progressCallback = noop ) {
84
85
let fulfill , reject ;
85
86
let totalBytes = 0 ;
@@ -135,19 +136,25 @@ function downloadFile(url, destinationPath, progressCallback = noop) {
135
136
return promise ;
136
137
}
137
138
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
- }
149
139
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
+ }
151
158
}
152
159
153
160
const release = (
@@ -169,13 +176,13 @@ const ffprobeUrl = `${baseUrl}/ffprobe-${platform}-${arch}`
169
176
const readmeUrl = `${ baseUrl } /${ platform } -${ arch } .README`
170
177
const licenseUrl = `${ baseUrl } /${ platform } -${ arch } .LICENSE`
171
178
172
- downloadFile ( ffmpegUrl , ffmpegPath , onProgress )
179
+ downloadFile ( ffmpegUrl , ffmpegPath , getProgressIndicator ( 'ffmpeg' ) )
173
180
. then ( ( ) => {
174
181
fs . chmodSync ( ffmpegPath , 0o755 ) // make executable
175
182
} )
176
183
. catch ( exitOnError )
177
184
178
- . then ( ( ) => downloadFile ( ffprobeUrl , ffprobePath , onProgress ) )
185
+ . then ( ( ) => downloadFile ( ffprobeUrl , ffprobePath , getProgressIndicator ( 'ffprobe' ) ) )
179
186
. then ( ( ) => {
180
187
fs . chmodSync ( ffprobePath , 0o755 ) // make executable
181
188
} )
0 commit comments