From 2990480ae6b7fd9cc30ad7e4825ec6b898022e21 Mon Sep 17 00:00:00 2001 From: guillaume-be Date: Fri, 11 Sep 2020 18:15:13 +0000 Subject: [PATCH] stream response to file buffer (#24) * stream response to file buffer * Updated changelog --- CHANGELOG.md | 4 ++++ src/cache.rs | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 606fb95..6503734 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- Updated the download method to stream the response into the target file. + ## [v0.4.2](https://github.com/epwalsh/rust-cached-path/releases/tag/v0.4.2) - 2020-09-11 ### Fixed diff --git a/src/cache.rs b/src/cache.rs index 596ea52..cb5fe82 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -7,7 +7,6 @@ use reqwest::header::ETAG; use std::default::Default; use std::env; use std::fs::{self, OpenOptions}; -use std::io::Write; use std::path::{Path, PathBuf}; use std::thread; use std::time::{self, Duration}; @@ -362,7 +361,7 @@ impl Cache { ) -> Result { debug!("Attempting connection to {}", url); - let response = self + let mut response = self .http_client .get(url.clone()) .send()? @@ -378,7 +377,7 @@ impl Cache { info!("Starting download of {}", url); - tempfile_write_handle.write_all(&response.bytes()?)?; + response.copy_to(&mut tempfile_write_handle)?; debug!("Writing meta file");