feat: commit unzip_file function

This commit is contained in:
mrxiaozhuox committed 2022-08-13 15:21:34 -07:00
1 parent d8506301eb
commit b28043a944
2 files changed
+12 -1

No files matched your search

+11
View File
@@ -5,6 +5,8 @@ use std::{
use mlua::UserData;
use crate::tools::extract_zip;
pub struct PluginFileSystem;
impl UserData for PluginFileSystem {
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
@@ -54,5 +56,14 @@ impl UserData for PluginFileSystem {
file.write_all(content.as_bytes())?;
Ok(())
});
methods.add_function("unzip_file", |_, args: (String, String)| {
let file = PathBuf::from(args.0);
let target = PathBuf::from(args.1);
let res = extract_zip(&file, &target);
if let Err(e) = res {
return Err(mlua::Error::RuntimeError(e.to_string()));
}
Ok(())
});
}
}
+1 -1
View File
@@ -313,7 +313,7 @@ impl Tool {
}
}
fn extract_zip(file: &Path, target: &Path) -> anyhow::Result<()> {
pub fn extract_zip(file: &Path, target: &Path) -> anyhow::Result<()> {
let zip_file = std::fs::File::open(&file)?;
let mut zip = zip::ZipArchive::new(zip_file)?;