aboutsummaryrefslogtreecommitdiffstats
path: root/src/archive.rs
diff options
context:
space:
mode:
authormarawan ragab <marawan31@gmail.com>2020-05-08 23:52:19 +0000
committermarawan ragab <marawan31@gmail.com>2020-05-08 23:52:19 +0000
commit3290edfbfe4c628553663243cbd439d9164c9029 (patch)
treec128a08565f0ed2d937d0e21bac7613ad84dac5e /src/archive.rs
parentadd zip download test (diff)
downloadminiserve-3290edfbfe4c628553663243cbd439d9164c9029.tar.gz
miniserve-3290edfbfe4c628553663243cbd439d9164c9029.zip
small improvment to buffer usage
Diffstat (limited to 'src/archive.rs')
-rw-r--r--src/archive.rs19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/archive.rs b/src/archive.rs
index 6808907..785e1e8 100644
--- a/src/archive.rs
+++ b/src/archive.rs
@@ -268,26 +268,19 @@ where
fn zip_data<W>(
src_dir: &Path,
skip_symlinks: bool,
- out: W,
+ mut out: W,
) -> Result<(), ContextualError>
where
W: std::io::Write,
{
let mut data = Vec::new();
- {
- let memory_file = Cursor::new(&mut data);
- create_zip_from_directory(memory_file, &src_dir.to_path_buf(), skip_symlinks).map_err(|e| {
- ContextualError::ArchiveCreationError("Failed to create the ZIP archive".to_string(), Box::new(e))
- })?;
- }
-
- let mut buffer = BufWriter::new(out);
- buffer.write_all(&mut data).map_err(|e| {
- ContextualError::IOError("Failed to write the ZIP archive".to_string(), e)
+ let memory_file = Cursor::new(&mut data);
+ create_zip_from_directory(memory_file, &src_dir.to_path_buf(), skip_symlinks).map_err(|e| {
+ ContextualError::ArchiveCreationError("Failed to create the ZIP archive".to_string(), Box::new(e))
})?;
- buffer.flush().map_err(|e| {
- ContextualError::IOError("Failed to finish writing the ZIP archive".to_string(), e)
+ out.write_all(data.as_mut_slice()).map_err(|e| {
+ ContextualError::IOError("Failed to write the ZIP archive".to_string(), e)
})?;
Ok(())