-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
185 add flag for download for ggetrs ensembl ref (#186)
* update blast testing since server updated their sorting * added functions for downloading urls async * download utils exposed publically * add stream feature to reqwest * include download utility for ensembl ref which downloads files inplace * ran cargo formatting * include download instructions on site * bump version
- Loading branch information
1 parent
b5694a1
commit a3081d3
Showing
9 changed files
with
72 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use anyhow::Result; | ||
use futures::{future::join_all, StreamExt}; | ||
use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; | ||
use reqwest::Client; | ||
use std::{fs::File, io::Write}; | ||
|
||
/// Download a file from a URL asynchronously | ||
async fn download_url(url: &str, pb: ProgressBar) -> Result<()> { | ||
let filename = url.split('/').last().unwrap_or(""); | ||
let client = Client::new().get(url).send().await?.error_for_status()?; | ||
|
||
let size = client.content_length().unwrap_or(0); | ||
pb.set_style(ProgressStyle::default_bar() | ||
.template( | ||
"{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({eta}) {msg}")? | ||
.progress_chars("#>-")); | ||
pb.set_length(size); | ||
pb.set_message(format!("{}", filename)); | ||
|
||
let mut file = File::create(filename)?; | ||
let mut stream = client.bytes_stream(); | ||
while let Some(item) = stream.next().await { | ||
let chunk = item?; | ||
pb.inc(chunk.len() as u64); | ||
file.write_all(&chunk)?; | ||
} | ||
pb.finish(); | ||
Ok(()) | ||
} | ||
|
||
/// Download multiple URLs asynchronously | ||
pub async fn download_multiple(urls: &[&str]) -> Result<()> { | ||
let mpb = MultiProgress::new(); | ||
let bars = (0..urls.len()).map(|_| mpb.add(ProgressBar::new(0))); | ||
let handles = urls.iter().zip(bars).map(|(url, pb)| download_url(url, pb)); | ||
join_all(handles).await; | ||
Ok(()) | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
pub mod autocomplete; | ||
mod download; | ||
mod fasta; | ||
pub mod parsing; | ||
mod ping; | ||
pub use download::download_multiple; | ||
pub use fasta::{FastaRecord, FastaRecords}; | ||
pub use ping::ping; |