now using the bytes package

This commit is contained in:
2023-02-06 17:40:40 +01:00
parent df1255d479
commit 48f0a44eaa
3 changed files with 9 additions and 6 deletions

1
Cargo.lock generated
View File

@@ -115,6 +115,7 @@ dependencies = [
name = "docki"
version = "0.2.0"
dependencies = [
"bytes",
"regex",
"reqwest",
"zip-extract",

View File

@@ -8,6 +8,7 @@ license-file = "LICENSE.txt"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bytes = "1.4.0"
regex = "1.7.1"
reqwest = {version = "0.11.14", features = ["blocking"]}
reqwest = { version = "0.11.14", features = ["blocking"] }
zip-extract = "0.1.1"

View File

@@ -1,12 +1,13 @@
use std::{collections::HashMap, env, fs::File, io::Write, fmt::format};
use std::{collections::HashMap, env, fs::File, io::Write};
use super::traits::Command;
use bytes::Bytes;
pub struct Setup;
impl Command for Setup {
fn execute(&self, _args: &HashMap<String, String>) -> Result<(), String> {
println!("setting up");
Self::setup();
return Ok(())
}
@@ -24,10 +25,10 @@ impl Setup {
let reveal_bin_url = format!("https://github.com/asciidoctor/asciidoctor-reveal.js/releases/download/v5.0.0-rc.1/asciidoctor-revealjs-{os}");
let reveal_bin = Self::donwload(&reveal_bin_url).expect("could not download asciidoctor binary");
let mut reveal_file = File::create("/usr/local/bin/asciidoctor").expect("could not save asciidoctor binary");
reveal_file.write_all(reveal_bin);
reveal_file.write_all(&reveal_bin).expect("could not save asciidoctor binary");
}
fn donwload(url: &str) -> Result<&[u8], ()> {
fn donwload(url: &str) -> Result<Bytes, ()> {
let Ok(response) = reqwest::blocking::get(url) else {
return Err(());
};
@@ -36,7 +37,7 @@ impl Setup {
return Err(());
};
return Ok(&data)
return Ok(data)
}
}