diff options
author | fxqnlr <[email protected]> | 2022-11-20 23:54:20 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-11-20 23:54:20 +0100 |
commit | c00673fd0e01d1438798dbb1635a761a76a2b559 (patch) | |
tree | 90c1f564fd7225e7312003c82ca269677cc5778d /src/lib.rs | |
parent | 477e0ecbb7bb34b581c518bfc2bc7ebc210b4673 (diff) | |
download | modlist-c00673fd0e01d1438798dbb1635a761a76a2b559.tar modlist-c00673fd0e01d1438798dbb1635a761a76a2b559.tar.gz modlist-c00673fd0e01d1438798dbb1635a761a76a2b559.zip |
extracted filedownload to fn;
fixed some tests;
added direct-dl to update
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -5,10 +5,12 @@ pub mod input; | |||
5 | pub mod db; | 5 | pub mod db; |
6 | pub mod error; | 6 | pub mod error; |
7 | 7 | ||
8 | use std::io::{Error, ErrorKind}; | 8 | use std::{io::{Error, ErrorKind, Write}, fs::File}; |
9 | 9 | ||
10 | pub use apis::*; | 10 | pub use apis::*; |
11 | pub use commands::*; | 11 | pub use commands::*; |
12 | use futures_util::StreamExt; | ||
13 | use reqwest::Client; | ||
12 | 14 | ||
13 | #[derive(Debug, Clone, PartialEq, Eq)] | 15 | #[derive(Debug, Clone, PartialEq, Eq)] |
14 | pub enum Modloader { | 16 | pub enum Modloader { |
@@ -32,3 +34,23 @@ impl Modloader { | |||
32 | } | 34 | } |
33 | } | 35 | } |
34 | } | 36 | } |
37 | |||
38 | pub 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 | } | ||