summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs25
1 files changed, 2 insertions, 23 deletions
diff --git a/src/lib.rs b/src/lib.rs
index e4ebf76..971f544 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,13 +4,12 @@ pub mod commands;
4pub mod input; 4pub mod input;
5pub mod db; 5pub mod db;
6pub mod error; 6pub mod error;
7pub mod files;
7 8
8use std::{io::{Error, ErrorKind, Write}, fs::File}; 9use std::io::{Error, ErrorKind};
9 10
10pub use apis::*; 11pub use apis::*;
11pub use commands::*; 12pub use commands::*;
12use futures_util::StreamExt;
13use reqwest::Client;
14 13
15#[derive(Debug, Clone, PartialEq, Eq)] 14#[derive(Debug, Clone, PartialEq, Eq)]
16pub enum Modloader { 15pub enum Modloader {
@@ -34,23 +33,3 @@ impl Modloader {
34 } 33 }
35 } 34 }
36} 35}
37
38pub async fn download_file(url: String, path: String, name: String) -> Result<(), Box<dyn std::error::Error>> {
39 println!("Downloading {}", url);
40 let dl_path_file = format!("{}/{}", path, name);
41 let res = Client::new()
42 .get(String::from(&url))
43 .send()
44 .await?;
45
46 // download chunks
47 let mut file = File::create(String::from(&dl_path_file))?;
48 let mut stream = res.bytes_stream();
49
50 while let Some(item) = stream.next().await {
51 let chunk = item?;
52 file.write_all(&chunk)?;
53 }
54
55 Ok(())
56}