diff options
author | marawan ragab <marawan31@gmail.com> | 2020-05-08 23:52:19 +0000 |
---|---|---|
committer | marawan ragab <marawan31@gmail.com> | 2020-05-08 23:52:19 +0000 |
commit | 3290edfbfe4c628553663243cbd439d9164c9029 (patch) | |
tree | c128a08565f0ed2d937d0e21bac7613ad84dac5e /src | |
parent | add zip download test (diff) | |
download | miniserve-3290edfbfe4c628553663243cbd439d9164c9029.tar.gz miniserve-3290edfbfe4c628553663243cbd439d9164c9029.zip |
small improvment to buffer usage
Diffstat (limited to '')
-rw-r--r-- | src/archive.rs | 19 |
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(()) |