aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariot Tsitoara <[email protected]>2021-01-03 22:40:38 +0100
committerMariot Tsitoara <[email protected]>2021-01-03 22:40:38 +0100
commiteea1bf4fbee230f16fd17a16f3d52167d40c2048 (patch)
tree553a982818bc07568d474b2dc2f6cd32605f0a83
parentAdd reload and sleep actions (diff)
downloadchan-downloader-eea1bf4fbee230f16fd17a16f3d52167d40c2048.tar.xz
chan-downloader-eea1bf4fbee230f16fd17a16f3d52167d40c2048.zip
Use bytes instead of text for image saving
-rw-r--r--Cargo.toml2
-rw-r--r--src/cli.yml2
-rw-r--r--src/lib.rs6
3 files changed, 5 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 71536b9..6e87776 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "chan-downloader"
description = "CLI to download all images/webms of a 4chan thread"
-version = "0.1.6"
+version = "0.1.7"
authors = ["Mariot Tsitoara <[email protected]>"]
edition = "2018"
license = "MIT"
diff --git a/src/cli.yml b/src/cli.yml
index 6b0ca8f..4819f45 100644
--- a/src/cli.yml
+++ b/src/cli.yml
@@ -1,5 +1,5 @@
name: chan-downloader
-version: "0.1.6"
+version: "0.1.7"
author: "Mariot Tsitoara <[email protected]>"
about: CLI to download all images/webms of a 4chan thread
args:
diff --git a/src/lib.rs b/src/lib.rs
index ec81c3b..cc16e09 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,7 +9,7 @@ extern crate regex;
extern crate reqwest;
use std::fs::File;
-use std::io::copy;
+use std::io::{copy, Cursor};
use log::info;
use regex::{CaptureMatches, Regex};
@@ -39,8 +39,8 @@ pub fn save_image(url: &str, path: &str, client: &Client) -> Result<String, Erro
if response.status().is_success() {
let mut dest = File::create(path).unwrap();
- let content = response.text()?;
- copy(&mut content.as_bytes(), &mut dest).unwrap();
+ let mut content = Cursor::new(response.bytes().unwrap());
+ copy(&mut content, &mut dest).unwrap();
}
info!("Saved image to: {}", path);
Ok(String::from(path))