From 1c2024c554a67e6d7f4583a3d3cc9ffa9dc39d49 Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Fri, 22 Jun 2018 15:46:38 +0200 Subject: [PATCH] Derivce Clone for ZipArchive --- src/read.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/read.rs b/src/read.rs index 85f76652..d6820a63 100644 --- a/src/read.rs +++ b/src/read.rs @@ -67,7 +67,7 @@ const TM_1980_01_01 : ::time::Tm = ::time::Tm { /// /// println!("Result: {:?}", doit()); /// ``` -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct ZipArchive { reader: R, @@ -688,4 +688,32 @@ mod test { } } } + + #[test] + fn zip_clone() { + use std::io::{self, Read}; + use super::ZipArchive; + + let mut v = Vec::new(); + v.extend_from_slice(include_bytes!("../tests/data/mimetype.zip")); + let mut reader1 = ZipArchive::new(io::Cursor::new(v)).unwrap(); + let mut reader2 = reader1.clone(); + + let mut file1 = reader1.by_index(0).unwrap(); + let mut file2 = reader2.by_index(0).unwrap(); + + let mut buf1 = [0; 5]; + let mut buf2 = [0; 5]; + let mut buf3 = [0; 5]; + let mut buf4 = [0; 5]; + + file1.read(&mut buf1).unwrap(); + file2.read(&mut buf2).unwrap(); + file1.read(&mut buf3).unwrap(); + file2.read(&mut buf4).unwrap(); + + assert_eq!(buf1, buf2); + assert_eq!(buf3, buf4); + assert!(buf1 != buf3); + } }