File tree Expand file tree Collapse file tree 2 files changed +19
-11
lines changed
Expand file tree Collapse file tree 2 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -18,17 +18,25 @@ async function downloadFile(url, outputPath) {
1818 }
1919
2020 const fileStream = fs . createWriteStream ( outputPath ) ;
21- const totalSize = parseInt ( response . headers . get ( 'content-length' ) , 10 ) ;
22- const progressBar = new ProgressBar ( 'Downloading [:bar] :percent :etas' , {
23- complete : '=' ,
24- incomplete : ' ' ,
25- width : 40 ,
26- total : totalSize ,
27- } ) ;
21+ const contentLength = response . headers . get ( 'content-length' ) ;
22+ let totalSize = parseInt ( contentLength , 10 ) ;
2823
29- response . body . on ( 'data' , ( chunk ) => {
30- progressBar . tick ( chunk . length ) ;
31- } ) ;
24+ if ( isNaN ( totalSize ) ) {
25+ console . warn (
26+ 'Warning: Size of the file is unknown. Progress bar will not be shown.'
27+ ) ;
28+ } else {
29+ const progressBar = new ProgressBar ( 'Downloading [:bar] :percent :etas' , {
30+ complete : '=' ,
31+ incomplete : ' ' ,
32+ width : 40 ,
33+ total : totalSize ,
34+ } ) ;
35+
36+ response . body . on ( 'data' , ( chunk ) => {
37+ progressBar . tick ( chunk . length ) ;
38+ } ) ;
39+ }
3240
3341 await new Promise ( ( resolve , reject ) => {
3442 response . body . pipe ( fileStream ) ;
Original file line number Diff line number Diff line change 11{
22 "name" : " @webredone/trb-cli" ,
3- "version" : " 3.0.4 " ,
3+ "version" : " 3.0.5 " ,
44 "description" : " TRB-CLI is a handy Node.js CLI that automates the process of managing blocks in a Theme Redone WordPress theme" ,
55 "main" : " index.js" ,
66 "type" : " module" ,
You can’t perform that action at this time.
0 commit comments