Skip to content

Commit

Permalink
stream response to file buffer (#24)
Browse files Browse the repository at this point in the history
* stream response to file buffer

* Updated changelog
  • Loading branch information
guillaume-be authored Sep 11, 2020
1 parent f162430 commit 2990480
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -362,7 +361,7 @@ impl Cache {
) -> Result<Meta, Error> {
debug!("Attempting connection to {}", url);

let response = self
let mut response = self
.http_client
.get(url.clone())
.send()?
Expand All @@ -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");

Expand Down

0 comments on commit 2990480

Please sign in to comment.