mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 16:14:48 +01:00
WIP: zip stuff
This commit is contained in:
33
src-tauri/src/unzip.rs
Normal file
33
src-tauri/src/unzip.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use zip;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
|
||||
#[tauri::command]
|
||||
pub fn unzip(zipfile: &str, zippath: &str, destpath: &str) {
|
||||
let mut f = match File::open(zipfile) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
println!("Failed to open zip file: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let mut reader = std::io::Cursor::new(&f);
|
||||
|
||||
let mut zip = match zip::ZipArchive::new(&f) {
|
||||
Ok(zip) => zip,
|
||||
Err(e) => {
|
||||
println!("Could not open zip file: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
for i in 0..zip.len()
|
||||
{
|
||||
let mut file = zip.by_index(i).unwrap();
|
||||
|
||||
println!("Filename: {}", file.name());
|
||||
let first_byte = file.bytes().next().unwrap();
|
||||
println!("{:?}", first_byte);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user