Last active
January 18, 2018 10:31
-
-
Save jhgaylor/8345292 to your computer and use it in GitHub Desktop.
Revisions
-
jhgaylor revised this gist
Jan 10, 2014 . 1 changed file with 3 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,7 @@ //given the urls of files to download, store them on the filesystem function download_all_files (urls, base_destination, job_id, cb) { var url = urls.shift(); var file_path = path.join(base_destination, job_id); // the path to the file without the filename var path_to_file_folder = path.dirname(file_path); @@ -18,7 +15,7 @@ file.on('finish', function() { file.close(); if(urls.length > 0){ download_all_files(urls, base_destination, job_id, cb); } else { cb(); } -
jhgaylor created this gist
Jan 10, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ //given the urls of files to download, store them on the filesystem function download_all_gnip_files (urls, base_destination, job_id, cb) { var url = urls.shift(); // gather the path from the url and throw away the query parameters var path_fragment = url.split('_'+job_id)[1].split("?")[0]; // the path to store the file var file_path = path.join(base_destination, job_id, path_fragment); // the path to the file without the filename var path_to_file_folder = path.dirname(file_path); // the method to store a downloaded file to the fs // makes an http request and writes the response to a file function download_url_to_fs () { var file = fs.createWriteStream(file_path); var request = https.get(url, function(response) { response.pipe(file); file.on('finish', function() { file.close(); if(urls.length > 0){ download_all_gnip_files(urls, base_destination, job_id, cb); } else { cb(); } }); }); } // bind download_url_to_fs to a meteor fiber var bound_download_url_to_fs = Meteor.bindEnvironment(download_url_to_fs, function (e) { throw e; }); // verify the required paths exist or create it // and then download the file to from http to the js mkdirp(path_to_file_folder, 0777, bound_download_url_to_fs); }