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.SevenZOutputFile;
@@ -17,10 +18,39 @@ import java.util.List;
* @author 夜雨
* @version 2024-06-30 19:40
*/
public class Z7Compressor extends Compressor {
public class Z7Compressor extends Compressor<Z7Compressor> {
/**
* 静态执行压缩
*
* @param fromPath 源路径
* @param toPath 目标文件路径
* @return 当前压缩器
* @throws Exception 压缩失败
*/
public static Z7Compressor 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 Z7Compressor run(String fromPath, String toPath, CallbackArg<File> fileCallback, CallbackArg<Double> progressCallback) throws Exception {
return new Z7Compressor()
.fileCallback(fileCallback)
.progressCallback(progressCallback)
.run(fromPath, IO.file(toPath));
}
@Override
public void run(String fromPath, OutputStream toStream) throws Exception {
protected void doRun(String fromPath, OutputStream toStream) throws Exception {
Path tempFile = Files.createTempFile("timi-compress-", ".7z");
try {
run(fromPath, tempFile.toFile());
@@ -34,7 +64,7 @@ public class Z7Compressor extends Compressor {
}
@Override
public void run(String fromPath, File toFile) throws Exception {
protected void doRunToFile(String fromPath, File toFile) throws Exception {
File fromFile = new File(fromPath);
List<File> files = IO.listFile(fromFile);
String basePath = files.getFirst().getParentFile().getAbsolutePath();