mirror of
https://github.com/Drop-OSS/droplet.git
synced 2025-11-22 04:31:26 +10:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e219ea13fb |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@drop-oss/droplet",
|
||||
"version": "3.4.0",
|
||||
"version": "3.5.0",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"napi": {
|
||||
|
||||
@ -111,6 +111,17 @@ impl VersionBackend for PathVersionBackend {
|
||||
|
||||
pub static SEVEN_ZIP_INSTALLED: LazyLock<bool> =
|
||||
LazyLock::new(|| Command::new("7z").output().is_ok());
|
||||
// https://7-zip.opensource.jp/chm/general/formats.htm
|
||||
// Intentionally repeated some because it's a trivial cost and it's easier to directly copy from the docs above
|
||||
pub const SUPPORTED_FILE_EXTENSIONS: [&str; 89] = [
|
||||
"7z", "bz2", "bzip2", "tbz2", "tbz", "gz", "gzip", "tgz", "tar", "wim", "swm", "esd", "xz",
|
||||
"txz", "zip", "zipx", "jar", "xpi", "odt", "ods", "docx", "xlsx", "epub", "apm", "ar", "a",
|
||||
"deb", "lib", "arj", "cab", "chm", "chw", "chi", "chq", "msi", "msp", "doc", "xls", "ppt",
|
||||
"cpio", "cramfs", "dmg", "ext", "ext2", "ext3", "ext4", "img", "fat", "img", "hfs", "hfsx",
|
||||
"hxs", "hxr", "hxq", "hxw", "lit", "ihex", "iso", "img", "lzh", "lha", "lzma", "mbr", "mslz",
|
||||
"mub", "nsis", "ntfs", "img", "mbr", "rar", "r00", "rpm", "ppmd", "qcow", "qcow2", "qcow2c",
|
||||
"squashfs", "udf", "iso", "img", "scap", "uefif", "vdi", "vhd", "vmdk", "xar", "pkg", "z", "taz",
|
||||
];
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ZipVersionBackend {
|
||||
@ -189,7 +200,12 @@ impl VersionBackend for ZipVersionBackend {
|
||||
continue;
|
||||
}
|
||||
results.push(VersionFile {
|
||||
relative_filename: name.into_iter().map(|v| *v).fold(String::new(), |a, b| a + b + " ").trim_end().to_owned(),
|
||||
relative_filename: name
|
||||
.into_iter()
|
||||
.map(|v| *v)
|
||||
.fold(String::new(), |a, b| a + b + " ")
|
||||
.trim_end()
|
||||
.to_owned(),
|
||||
permission: 0o744, // owner r/w/x, everyone else, read
|
||||
size: size.parse().unwrap(),
|
||||
});
|
||||
|
||||
@ -10,7 +10,9 @@ use napi::{bindgen_prelude::*, sys::napi_value__, tokio_stream::StreamExt};
|
||||
use tokio_util::codec::{BytesCodec, FramedRead};
|
||||
|
||||
use crate::version::{
|
||||
backends::{PathVersionBackend, ZipVersionBackend, SEVEN_ZIP_INSTALLED},
|
||||
backends::{
|
||||
PathVersionBackend, ZipVersionBackend, SEVEN_ZIP_INSTALLED, SUPPORTED_FILE_EXTENSIONS,
|
||||
},
|
||||
types::{ReadToAsyncRead, VersionBackend, VersionFile},
|
||||
};
|
||||
|
||||
@ -33,6 +35,8 @@ pub fn create_backend_constructor<'a>(
|
||||
};
|
||||
|
||||
if *SEVEN_ZIP_INSTALLED {
|
||||
/*
|
||||
Slow 7zip integrity test
|
||||
let mut test = Command::new("7z");
|
||||
test.args(vec!["t", path.to_str().expect("invalid utf path")]);
|
||||
let status = test.status().ok()?;
|
||||
@ -40,6 +44,18 @@ pub fn create_backend_constructor<'a>(
|
||||
let buf = path.to_path_buf();
|
||||
return Some(Box::new(move || Ok(Box::new(ZipVersionBackend::new(buf)?))));
|
||||
}
|
||||
*/
|
||||
// Fast filename-based test
|
||||
if let Some(extension) = path.extension().and_then(|v| v.to_str()) {
|
||||
let supported = SUPPORTED_FILE_EXTENSIONS
|
||||
.iter()
|
||||
.find(|v| ***v == *extension)
|
||||
.is_some();
|
||||
if supported {
|
||||
let buf = path.to_path_buf();
|
||||
return Some(Box::new(move || Ok(Box::new(ZipVersionBackend::new(buf)?))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user