From 3290edfbfe4c628553663243cbd439d9164c9029 Mon Sep 17 00:00:00 2001 From: marawan ragab Date: Fri, 8 May 2020 19:52:19 -0400 Subject: small improvment to buffer usage --- src/archive.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/archive.rs') 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( 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(()) -- cgit v1.2.3