1pub mod archive;
40pub mod error;
41pub mod traits;
42pub mod types;
43pub mod utils;
44
45#[cfg(feature = "cli")]
46pub mod cli;
47
48#[cfg(feature = "convert")]
49pub mod convert;
50
51pub use error::{ArchiveError, Result};
53pub use types::{File, Fmt};
54pub use utils::{clean, human_size, mode_to_string};
55
56#[cfg(feature = "decode")]
57pub use traits::Decode;
58
59#[cfg(feature = "encode")]
60pub use traits::Encode;
61
62#[cfg(feature = "encode")]
63pub use utils::check_duplicate_files;
64
65#[cfg(all(feature = "encode", feature = "decode"))]
66pub use traits::Archive;
67
68#[cfg(feature = "convert")]
69pub use convert::{convert_archive, convert_archive_file};
70
71#[cfg(test)]
72mod test {
73 use crate::{File, types::Fmt};
74 use strum::IntoEnumIterator;
75
76 #[test]
77 fn test_decode() {
78 for name in std::fs::read_dir("../assets").unwrap() {
79 let path = name.unwrap().path();
80 let buffer = std::fs::read(&path).unwrap();
81 let fmt = Fmt::guess(&path.to_string_lossy()).unwrap();
82 let files = fmt.decode(buffer).unwrap();
83 let dist = files
84 .iter()
85 .find(|i| i.path == "mujs-build-0.0.11/dist-manifest.json")
86 .unwrap();
87 assert!(!dist.buffer.is_empty());
88 }
89 }
90
91 use std::path::PathBuf;
92
93 #[test]
94 fn encode_decode() {
95 for fmt in Fmt::iter() {
96 #[cfg(feature = "tar-bz")]
98 if fmt == Fmt::TarBz {
99 continue;
101 }
102
103 let mut files = vec![];
104 let base = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
105 let asset_dir = base.join("../assets");
106
107 for entry in std::fs::read_dir(asset_dir).expect("read dir error") {
108 let file_path = entry.expect("get path error").path();
109 let path = file_path
110 .file_name()
111 .expect("get name error")
112 .to_string_lossy()
113 .to_string();
114 let buffer = std::fs::read(&file_path).expect("read file error");
115
116 files.push(File {
117 buffer,
118 path,
119 mode: None,
120 is_dir: false,
121 last_modified: None,
122 })
123 }
124
125 let compressed = fmt.encode(files).expect("encode error");
126 println!("{:?} {}", fmt, compressed.len());
127 assert!(!compressed.is_empty());
128 }
129 }
130}