Download files in parallel

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
8
down vote

favorite












This module has a ensure_downloaded function which takes a slice of Urls. It downloads all of the urls to a local downloads folder (if they aren't already downloaded) and returns.



use curl::easy::Easy;
use failure::Error;
use pbr::ProgressBar, Units;
use std::fs::rename, DirBuilder, File;
use std::io::Write;
use std::path::PathBuf;
use std::sync::Arc, Mutex;
use std::thread;
use std::time::Duration;
use url::Url;

/// Return the local path where the given url will be stored.
pub fn downloaded_path(url: &Url) -> PathBuf
PathBuf::from("downloads")
.join(url.host_str().unwrap())
.join(&url.path()[1..])


/// Ensure that all the urls are downloaded into a local downloads directory.
pub fn ensure_downloaded(urls: &[&Url]) -> Result<(), Error> (url, path)






share|improve this question

























    up vote
    8
    down vote

    favorite












    This module has a ensure_downloaded function which takes a slice of Urls. It downloads all of the urls to a local downloads folder (if they aren't already downloaded) and returns.



    use curl::easy::Easy;
    use failure::Error;
    use pbr::ProgressBar, Units;
    use std::fs::rename, DirBuilder, File;
    use std::io::Write;
    use std::path::PathBuf;
    use std::sync::Arc, Mutex;
    use std::thread;
    use std::time::Duration;
    use url::Url;

    /// Return the local path where the given url will be stored.
    pub fn downloaded_path(url: &Url) -> PathBuf
    PathBuf::from("downloads")
    .join(url.host_str().unwrap())
    .join(&url.path()[1..])


    /// Ensure that all the urls are downloaded into a local downloads directory.
    pub fn ensure_downloaded(urls: &[&Url]) -> Result<(), Error> (url, path)






    share|improve this question





















      up vote
      8
      down vote

      favorite









      up vote
      8
      down vote

      favorite











      This module has a ensure_downloaded function which takes a slice of Urls. It downloads all of the urls to a local downloads folder (if they aren't already downloaded) and returns.



      use curl::easy::Easy;
      use failure::Error;
      use pbr::ProgressBar, Units;
      use std::fs::rename, DirBuilder, File;
      use std::io::Write;
      use std::path::PathBuf;
      use std::sync::Arc, Mutex;
      use std::thread;
      use std::time::Duration;
      use url::Url;

      /// Return the local path where the given url will be stored.
      pub fn downloaded_path(url: &Url) -> PathBuf
      PathBuf::from("downloads")
      .join(url.host_str().unwrap())
      .join(&url.path()[1..])


      /// Ensure that all the urls are downloaded into a local downloads directory.
      pub fn ensure_downloaded(urls: &[&Url]) -> Result<(), Error> (url, path)






      share|improve this question











      This module has a ensure_downloaded function which takes a slice of Urls. It downloads all of the urls to a local downloads folder (if they aren't already downloaded) and returns.



      use curl::easy::Easy;
      use failure::Error;
      use pbr::ProgressBar, Units;
      use std::fs::rename, DirBuilder, File;
      use std::io::Write;
      use std::path::PathBuf;
      use std::sync::Arc, Mutex;
      use std::thread;
      use std::time::Duration;
      use url::Url;

      /// Return the local path where the given url will be stored.
      pub fn downloaded_path(url: &Url) -> PathBuf
      PathBuf::from("downloads")
      .join(url.host_str().unwrap())
      .join(&url.path()[1..])


      /// Ensure that all the urls are downloaded into a local downloads directory.
      pub fn ensure_downloaded(urls: &[&Url]) -> Result<(), Error> (url, path)








      share|improve this question










      share|improve this question




      share|improve this question









      asked May 13 at 2:39









      Winston Ewert

      26.1k44374




      26.1k44374

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f194290%2fdownload-files-in-parallel%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f194290%2fdownload-files-in-parallel%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Chat program with C++ and SFML

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          Will my employers contract hold up in court?