Skip to content

Instantly share code, notes, and snippets.

@rrichardson
Created August 24, 2019 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrichardson/d2221b3f904fe53bf650b880495ffa2f to your computer and use it in GitHub Desktop.
Save rrichardson/d2221b3f904fe53bf650b880495ffa2f to your computer and use it in GitHub Desktop.
let jobs = myvec
.into_iter()
.map(|url| {
// we use the end of the supplied URL to create the directory
let uri = url.parse::<Uri>().unwrap();
let p = uri.path();
let segments = p.split('/').collect::<Vec<_>>();
let end = &segments[segments.len() - 4..];
let fullpath = Path::new(&ctx.config.data_dir).join(end.join("/"));
std::fs::create_dir_all(fullpath.parent().unwrap()).unwrap();
requests::fetch_to_disk(uri, fullpath)
});
let fut = futures::stream::futures_unordered(jobs).collect();
let _result = runtime.block_on(fut).unwrap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment