File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,13 +20,15 @@ RepositoryDownloader.prototype.fetch = function(destination) {
2020 download = require ( 'download' ) ,
2121 totalSize ,
2222 receivedSize ,
23- previousPercent = 0 ;
23+ previousPercent = 0 ,
24+ fileName = '' ;
2425
2526 download ( this . url , destination , {
2627 extract : true
2728 } )
2829 . on ( 'response' , function ( response ) {
2930 totalSize = Number ( response . headers [ 'content-length' ] ) ;
31+ fileName = getFileName ( response . headers [ 'content-disposition' ] ) ;
3032 receivedSize = 0 ;
3133 } )
3234 . on ( 'data' , function ( data ) {
@@ -46,11 +48,23 @@ RepositoryDownloader.prototype.fetch = function(destination) {
4648 deferred . reject ( err ) ;
4749 } )
4850 . then ( function ( ) {
49- deferred . resolve ( destination ) ;
51+ deferred . resolve ( fileName ) ;
5052 } ) ;
5153
5254 return deferred . promise ;
5355} ;
5456
57+ function getFileName ( disposition ) {
58+ var fileName = "" ;
59+ if ( disposition && disposition . indexOf ( 'attachment' ) !== - 1 ) {
60+ var regex = / f i l e n a m e [ ^ ; = \n ] * = ( ( [ ' " ] ) .* ?\2| [ ^ ; \n ] * ) / ;
61+ var matches = regex . exec ( disposition ) ;
62+ if ( matches != null && matches [ 1 ] ) {
63+ fileName = matches [ 1 ] . replace ( / [ ' " ] / g, '' ) ;
64+ }
65+ }
66+ return fileName ;
67+ }
68+
5569module . exports = RepositoryDownloader ;
5670
You can’t perform that action at this time.
0 commit comments