Skip to content

Commit

Permalink
use chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mon-ius committed May 13, 2024
1 parent 129c977 commit 04e9007
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion hfd-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hfd-cli"
version = "0.2.4"
version = "0.2.5"
edition = "2021"

[dependencies]
Expand Down
30 changes: 16 additions & 14 deletions hfd-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,24 +213,26 @@ impl HfClient {
}

pub async fn download_all(&self) -> Result<(), Box<dyn std::error::Error>> {
let mut tasks = Vec::new();

let files = self.list_files().await?;
let _ = self.create_dir_all(files.clone());

for file in files{
let url = self.hf_url.path(&file);
let path = self.root.join(&file);
let headers = self.headers.clone();
tasks.push(tokio::spawn(async move {
download(headers, url, path, CHUNK_SIZE).await;
std::thread::sleep(Duration::from_millis(10));
}));
}
for chunks in files.chunks(50){
let mut tasks = Vec::new();

for file in chunks{
let url = self.hf_url.path(&file);
let path = self.root.join(&file);
let headers = self.headers.clone();
tasks.push(tokio::spawn(async move {
download(headers, url, path, CHUNK_SIZE).await;
std::thread::sleep(Duration::from_millis(10));
}));
}

for task in tasks {
task.await.unwrap();
std::thread::sleep(Duration::from_millis(100));
for task in tasks {
task.await.unwrap();
std::thread::sleep(Duration::from_millis(100));
}
}
Ok(())
}
Expand Down

0 comments on commit 04e9007

Please sign in to comment.