use std::io::{BufWriter, Write};
use fetch::HttpClient;
use futures::TryStreamExt;
#[tokio::main]
async fn main() -> Result<(), ohno::AppError> {
let client = HttpClient::new_tokio();
let body = client.get("https://example.com").fetch().await?.into_body();
let mut stream = body.into_stream();
let mut file = BufWriter::new(std::fs::File::create("output.txt")?);
while let Some(mut chunk) = stream.try_next().await? {
let size = chunk.len();
std::io::copy(&mut chunk, &mut file)?;
println!("Chunk stored to a file, size: {size}");
}
file.flush()?;
println!("File download completed.");
std::fs::remove_file("output.txt")?;
Ok(())
}