Skip to content

Commit

Permalink
wip run download
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Apr 1, 2024
1 parent 2d74a14 commit 788c1c4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions checked_cli/src/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
use std::io::{BufWriter, Write};
use std::sync::Arc;
use std::sync::atomic::{AtomicI64, AtomicUsize};
use crate::cli::FetchArgs;
use anyhow::Context;

struct FetchState {
asset_size: AtomicUsize,
downloaded_size: AtomicI64,
}

pub async fn fetch(fetch_args: FetchArgs) -> anyhow::Result<()> {
let fetch_url = url::Url::parse(&fetch_args.url).context("Invalid URL")?;
let tmp_file = tempfile::Builder::new()
Expand Down Expand Up @@ -28,8 +36,9 @@ pub async fn fetch(fetch_args: FetchArgs) -> anyhow::Result<()> {

let mut res = reqwest::get(fetch_args.url).await?;

while let Some(c) = res.chunk()? {
tmp_file.as_file_mut().write_all(&c)?;
let mut writer = BufWriter::new(tmp_file.as_file());
while let Some(c) = res.chunk().await? {
writer.write_all(&c)?;
}

println!("Did initial request");
Expand All @@ -44,3 +53,7 @@ pub async fn fetch(fetch_args: FetchArgs) -> anyhow::Result<()> {

Ok(())
}

async fn run_download(fetch_url: String, state: Arc<FetchState>) {

}

0 comments on commit 788c1c4

Please sign in to comment.