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

This commit is contained in:
Timi
2026-04-02 16:23:53 +08:00
parent 56dec33c94
commit b56f4e8969
19 changed files with 372 additions and 282 deletions

View File

@@ -1,7 +1,6 @@
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;
@@ -21,39 +20,30 @@ import java.util.List;
public class Z7Compressor extends Compressor<Z7Compressor> {
/**
* 静态执行压缩
* 创建压缩
*
* @param fromPath 源路径
* @param toPath 目标文件路径
* @return 当前压缩器
* @throws Exception 压缩失败
* @return 压缩器
*/
public static Z7Compressor run(String fromPath, String toPath) throws Exception {
return run(fromPath, toPath, null, null);
public static Z7Compressor of(String fromPath) {
return new Z7Compressor().from(fromPath);
}
/**
* 静态执行压缩
* 创建压缩
*
* @param fromPath 源路径
* @param toPath 目标文件路径
* @param fileCallback 文件处理回调
* @param progressCallback 进度回调
* @return 当前压缩器
* @throws Exception 压缩失败
* @param fromFile 源文件
* @return 压缩器
*/
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));
public static Z7Compressor of(File fromFile) {
return new Z7Compressor().from(fromFile);
}
@Override
protected void doRun(String fromPath, OutputStream toStream) throws Exception {
protected void toStream(String fromPath, OutputStream toStream) throws Exception {
Path tempFile = Files.createTempFile("timi-compress-", ".7z");
try {
run(fromPath, tempFile.toFile());
from(fromPath).toFile(tempFile.toFile());
try (InputStream inputStream = Files.newInputStream(tempFile)) {
transfer(inputStream, toStream, false);
toStream.flush();
@@ -64,7 +54,7 @@ public class Z7Compressor extends Compressor<Z7Compressor> {
}
@Override
protected void doRunToFile(String fromPath, File toFile) throws Exception {
protected void toFile(String fromPath, File toFile) throws Exception {
File fromFile = new File(fromPath);
List<File> files = IO.listFile(fromFile);
String basePath = files.getFirst().getParentFile().getAbsolutePath();