v0.0.2
All checks were successful
CI/CD / build-deploy (pull_request) Successful in 14s

This commit is contained in:
Timi
2026-04-01 22:47:09 +08:00
parent a24b1855aa
commit 56dec33c94
17 changed files with 550 additions and 69 deletions

View File

@@ -1,6 +1,7 @@
package com.imyeyu.compress;
import com.imyeyu.io.IO;
import com.imyeyu.java.bean.CallbackArg;
import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
import org.apache.commons.compress.archivers.sevenz.SevenZFile;
@@ -16,20 +17,49 @@ import java.nio.file.Path;
* @author 夜雨
* @version 2024-06-30 19:42
*/
public class Z7Decompressor extends Decompressor {
public class Z7Decompressor extends Decompressor<Z7Decompressor> {
/**
* 静态执行解压
*
* @param fromPath 源压缩文件路径
* @param toPath 目标目录路径
* @return 当前解压器
* @throws Exception 解压失败
*/
public static Z7Decompressor run(String fromPath, String toPath) throws Exception {
return run(fromPath, toPath, null, null);
}
/**
* 静态执行解压
*
* @param fromPath 源压缩文件路径
* @param toPath 目标目录路径
* @param fileCallback 文件处理回调
* @param progressCallback 进度回调
* @return 当前解压器
* @throws Exception 解压失败
*/
public static Z7Decompressor run(String fromPath, String toPath, CallbackArg<File> fileCallback, CallbackArg<Double> progressCallback) throws Exception {
return new Z7Decompressor()
.fileCallback(fileCallback)
.progressCallback(progressCallback)
.run(IO.file(fromPath), toPath);
}
@Override
public void run(File fromFile, String toPath) throws Exception {
protected void doRunFromFile(File fromFile, String toPath) throws Exception {
initByteProgress(readTotalSize(fromFile));
try {
super.run(fromFile, toPath);
super.doRunFromFile(fromFile, toPath);
} finally {
resetProgress();
}
}
@Override
public void run(InputStream fromStream, String toPath) throws Exception {
protected void doRun(InputStream fromStream, String toPath) throws Exception {
Path tempFile = writeTempFile(fromStream);
try (SevenZFile file = SevenZFile.builder().setFile(tempFile.toFile()).get()) {
SevenZArchiveEntry entry;