mirror of
https://github.com/tealdeer-rs/tealdeer.git
synced 2026-08-23 00:24:17 +02:00
Merge pull request #61 from jcgruenhage/master
Move from curl to reqwest
This commit is contained in:
commit
d950700746
8 changed files with 856 additions and 59 deletions
|
|
@ -2,7 +2,7 @@ version: 2
|
|||
jobs:
|
||||
build:
|
||||
docker:
|
||||
- image: rust:1.28
|
||||
- image: rust:1.30
|
||||
steps:
|
||||
- checkout
|
||||
# Load cargo target from cache if possible.
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
language: rust
|
||||
os: osx
|
||||
rust:
|
||||
- 1.28.0
|
||||
- 1.30.0
|
||||
- stable
|
||||
cache: cargo
|
||||
script: cargo test
|
||||
|
|
|
|||
878
Cargo.lock
generated
878
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -16,7 +16,6 @@ path = "src/main.rs"
|
|||
[dependencies]
|
||||
ansi_term = "0.10.2"
|
||||
clippy = { version = "0.0.174", optional = true }
|
||||
curl = "0.4.15"
|
||||
docopt = "0.8.1"
|
||||
env_logger = { version = "0.5", optional = true }
|
||||
flate2 = "1.0"
|
||||
|
|
@ -28,6 +27,7 @@ time = "0.1.38"
|
|||
toml = "0.4.6"
|
||||
walkdir = "2.0.1"
|
||||
xdg = "2.1.0"
|
||||
reqwest = "0.9.5"
|
||||
|
||||
[dev-dependencies]
|
||||
tempdir = "^0.3"
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ Build and install the tool via cargo...
|
|||
|
||||
### From Source (any platform)
|
||||
|
||||
tealdeer requires at least Rust 1.28.
|
||||
tealdeer requires at least Rust 1.30.
|
||||
|
||||
Debug build with logging enabled:
|
||||
|
||||
|
|
|
|||
19
src/cache.rs
19
src/cache.rs
|
|
@ -6,7 +6,7 @@ use std::path::PathBuf;
|
|||
#[cfg(unix)]
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
|
||||
use curl::easy::Easy as CurlEasy;
|
||||
use reqwest;
|
||||
use flate2::read::GzDecoder;
|
||||
use tar::Archive;
|
||||
use time;
|
||||
|
|
@ -61,19 +61,10 @@ impl Cache {
|
|||
|
||||
/// Download the archive
|
||||
fn download(&self) -> Result<Vec<u8>, TealdeerError> {
|
||||
let mut handle = CurlEasy::new();
|
||||
try!(handle.url(&self.url));
|
||||
try!(handle.follow_location(true));
|
||||
try!(handle.fail_on_error(true));
|
||||
let mut buf = Vec::new();
|
||||
{
|
||||
let mut transfer = handle.transfer();
|
||||
try!(transfer.write_function(|data| {
|
||||
buf.extend_from_slice(data);
|
||||
Ok(data.len())
|
||||
}));
|
||||
try!(transfer.perform());
|
||||
}
|
||||
let mut resp = reqwest::get(&self.url)?;
|
||||
let mut buf: Vec<u8> = vec![];
|
||||
let bytes_downloaded = resp.copy_to(&mut buf)?;
|
||||
debug!("{} bytes downloaded", bytes_downloaded);
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use std::fmt;
|
||||
use curl::Error as CurlError;
|
||||
use reqwest::Error as ReqwestError;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum TealdeerError {
|
||||
|
|
@ -8,9 +8,9 @@ pub enum TealdeerError {
|
|||
UpdateError(String),
|
||||
}
|
||||
|
||||
impl From<CurlError> for TealdeerError {
|
||||
fn from(err: CurlError) -> TealdeerError {
|
||||
TealdeerError::UpdateError(format!("Curl error: {}", err.to_string()))
|
||||
impl From<ReqwestError> for TealdeerError {
|
||||
fn from(err: ReqwestError) -> TealdeerError {
|
||||
TealdeerError::UpdateError(format!("HTTP error: {}", err.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@
|
|||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate ansi_term;
|
||||
extern crate curl;
|
||||
extern crate reqwest;
|
||||
extern crate docopt;
|
||||
#[cfg(feature = "logging")]
|
||||
extern crate env_logger;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue