zip_extensions/
lib.rs

1#![allow(dead_code)]
2
3pub use crate::read::*;
4pub use crate::write::*;
5
6mod file_utils;
7pub mod read;
8pub mod write;
9
10#[cfg(test)]
11mod tests {
12    use crate::is_zip;
13    use std::fs::{self, File};
14    use std::path::PathBuf;
15    use std::str::FromStr;
16
17    #[test]
18    fn is_zip_returns_false_if_file_does_not_exists() {
19        let archive_file = PathBuf::from_str("missing.zip").unwrap();
20        let actual = is_zip(&archive_file);
21        assert_eq!(actual, false)
22    }
23
24    #[test]
25    fn is_zip_returns_true() {
26        let archive_file = PathBuf::from_str("empty.zip").unwrap();
27        let file = File::create(&archive_file.as_path()).unwrap();
28        let mut zip_writer = zip::ZipWriter::new(file);
29        zip_writer.set_comment("This is an empty ZIP file.");
30        zip_writer.finish().unwrap();
31        let actual = is_zip(&archive_file);
32        fs::remove_file(&archive_file.as_path()).unwrap();
33        assert_eq!(actual, true)
34    }
35}