Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Commit d23716d

Browse files
committed
use async stdout
1 parent 2d56928 commit d23716d

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ reqwest = { version = "0.12.15", default-features = false, features = ["rustls-t
3131
serde = { version = "1.0.219", features = ["derive"] }
3232
serde_json = "1.0.140"
3333
tar = "0.4.44"
34-
tokio = { version = "1.44.2", features = ["macros", "rt-multi-thread"] }
34+
tokio = { version = "1.44.2", features = ["io-std", "macros", "rt-multi-thread"] }
3535
url = "2.5.4"
3636
xz2 = "0.1.7"
3737
zip = "2.6.1"

src/downloader.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use std::{
22
collections::{HashMap, HashSet},
33
fs::Permissions,
4-
io::Write,
54
os::unix::fs::PermissionsExt,
65
path::{Path, PathBuf},
76
sync::{Arc, Mutex},
87
};
98

10-
use futures::{future::join_all, StreamExt, TryStreamExt};
9+
use futures::{future::join_all, TryStreamExt};
1110
use regex::Regex;
1211
use reqwest::header::{HeaderMap, CONTENT_DISPOSITION, ETAG, LAST_MODIFIED};
1312

@@ -183,14 +182,16 @@ impl Downloader<'_> {
183182
}
184183

185184
if options.output_path.as_deref() == Some("-") {
186-
let stdout = std::io::stdout();
187-
let mut stdout_lock = stdout.lock();
185+
let mut stdout = tokio::io::stdout();
188186
let mut stream = response.bytes_stream();
189187

190-
while let Some(chunk) = stream.next().await {
191-
let chunk = chunk.unwrap();
192-
stdout_lock.write_all(&chunk).unwrap();
193-
stdout_lock.flush().unwrap();
188+
while let Some(chunk) = stream
189+
.try_next()
190+
.await
191+
.map_err(|_| DownloadError::ChunkError)?
192+
{
193+
stdout.write_all(&chunk).await?;
194+
stdout.flush().await?;
194195
}
195196
return Ok("-".to_string());
196197
}

0 commit comments

Comments
 (0)