@@ -18,30 +18,24 @@ var RepositoryDownloader = function(options) {
1818RepositoryDownloader . prototype . fetch = function ( destination ) {
1919 var deferred = Q . defer ( ) ,
2020 download = require ( 'download' ) ,
21- totalSize ,
22- receivedSize ,
2321 previousPercent = 0 ,
2422 fileName = '' ;
2523
2624 download ( this . url , destination , {
2725 extract : true
2826 } )
2927 . on ( 'response' , function ( response ) {
30- totalSize = Number ( response . headers [ 'content-length' ] ) ;
3128 fileName = getFileName ( response . headers [ 'content-disposition' ] ) ;
32- receivedSize = 0 ;
3329 } )
34- . on ( 'data' , function ( data ) {
35- receivedSize += data . length ;
36-
30+ . on ( 'downloadProgress' , function ( progress ) {
3731 var state = {
38- receivedSize : receivedSize ,
39- percent : totalSize ? Math . round ( receivedSize / totalSize * 100 ) : null
32+ receivedSize : progress . transferred ,
33+ percent : Math . round ( progress . transferred / progress . total * 100 )
4034 } ;
4135
4236 if ( state . percent > previousPercent ) {
4337 previousPercent = state . percent ;
44- deferred . notify ( state , data ) ;
38+ deferred . notify ( state , progress ) ;
4539 }
4640 } )
4741 . on ( 'error' , function ( err ) {
0 commit comments