File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -47,12 +47,20 @@ process.on('message', function(task) {
4747 */
4848 function downloadFile ( cb ) {
4949 if ( task . file_path ) {
50+ var stream = fs . createWriteStream ( path ) ;
51+
52+ var binaryParser = function binaryParser ( res , cb ) {
53+ stream . on ( 'end' , cb ) ;
54+ res . pipe ( stream ) ;
55+ } ;
56+
5057 // Download the file
5158 var apiUrl = url . parse ( task . file_path , false , true ) ;
5259 request ( apiUrl . protocol + "//" + apiUrl . host )
5360 . get ( apiUrl . path )
5461 . expect ( 200 )
55- . end ( function ( err , res ) {
62+ . parse ( binaryParser )
63+ . end ( function ( err ) {
5664 if ( err ) {
5765 if ( err . toString ( ) . match ( / 4 1 0 / ) ) {
5866 err . skip = true ;
@@ -62,7 +70,8 @@ process.on('message', function(task) {
6270 }
6371 return cb ( err ) ;
6472 }
65- fs . writeFile ( path , res . text , { encoding : 'binary' } , cb ) ;
73+ stream . end ( ) ;
74+ cb ( ) ;
6675 } ) ;
6776 }
6877 else {
You can’t perform that action at this time.
0 commit comments