diff options
author | fxqnlr <[email protected]> | 2022-11-28 22:55:14 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-11-28 22:55:14 +0100 |
commit | ddde9204c72dd867f920f07f6483be03dda7cf68 (patch) | |
tree | 51ee1140311be4a82a7832bcef2772db7fd4e639 /src/lib.rs | |
parent | d8cb7bc5f9c2e01c82f954427a60da6eaf0610ca (diff) | |
download | modlist-ddde9204c72dd867f920f07f6483be03dda7cf68.tar modlist-ddde9204c72dd867f920f07f6483be03dda7cf68.tar.gz modlist-ddde9204c72dd867f920f07f6483be03dda7cf68.zip |
basically update impl; added "good" download;
auto dl on new mod; db to 0.4; etc
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 25 |
1 files changed, 2 insertions, 23 deletions
@@ -4,13 +4,12 @@ pub mod commands; | |||
4 | pub mod input; | 4 | pub mod input; |
5 | pub mod db; | 5 | pub mod db; |
6 | pub mod error; | 6 | pub mod error; |
7 | pub mod files; | ||
7 | 8 | ||
8 | use std::{io::{Error, ErrorKind, Write}, fs::File}; | 9 | use std::io::{Error, ErrorKind}; |
9 | 10 | ||
10 | pub use apis::*; | 11 | pub use apis::*; |
11 | pub use commands::*; | 12 | pub use commands::*; |
12 | use futures_util::StreamExt; | ||
13 | use reqwest::Client; | ||
14 | 13 | ||
15 | #[derive(Debug, Clone, PartialEq, Eq)] | 14 | #[derive(Debug, Clone, PartialEq, Eq)] |
16 | pub enum Modloader { | 15 | pub enum Modloader { |
@@ -34,23 +33,3 @@ impl Modloader { | |||
34 | } | 33 | } |
35 | } | 34 | } |
36 | } | 35 | } |
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 | } | ||