v0.0.3
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
@@ -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.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
@@ -12,7 +11,6 @@ import java.io.OutputStream;
/**
* Gzip 解压器
* 当前实现保持与原行为一致,实际按 tar.gz 解压
*
* @author 夜雨
* @version 2024-06-30 19:47
@@ -20,46 +18,47 @@ import java.io.OutputStream;
public class GZipDecompressor extends Decompressor<GZipDecompressor> {
/**
* 静态执行解压
* 创建解压器
*
* @param fromPath 源压缩文件路径
* @param toPath 目标目录路径
* @return 当前解压器
* @throws Exception 解压失败
* @param fromFile 源压缩文件
* @return 解压器
*/
public static GZipDecompressor run(String fromPath, String toPath) throws Exception {
return run(fromPath, toPath, null, null);
public static GZipDecompressor of(File fromFile) {
return new GZipDecompressor().from(fromFile);
}
/**
* 静态执行解压
* 创建解压器
*
* @param fromPath 源压缩文件路径
* @param toPath 目标目录路径
* @param fileCallback 文件处理回调
* @param progressCallback 进度回调
* @return 当前解压器
* @throws Exception 解压失败
* @return 解压器
*/
public static GZipDecompressor run(String fromPath, String toPath, CallbackArg<File> fileCallback, CallbackArg<Double> progressCallback) throws Exception {
return new GZipDecompressor()
.fileCallback(fileCallback)
.progressCallback(progressCallback)
.run(IO.file(fromPath), toPath);
public static GZipDecompressor of(String fromPath) {
return new GZipDecompressor().from(fromPath);
}
/**
* 创建解压器
*
* @param fromStream 源压缩输入流
* @return 解压器
*/
public static GZipDecompressor of(InputStream fromStream) {
return new GZipDecompressor().from(fromStream);
}
@Override
protected void doRunFromFile(File fromFile, String toPath) throws Exception {
protected void toPath(File fromFile, String toPath) throws Exception {
initByteProgress(readTotalSize(fromFile));
try {
super.doRunFromFile(fromFile, toPath);
super.toPath(fromFile, toPath);
} finally {
resetProgress();
}
}
@Override
protected void doRun(InputStream fromStream, String toPath) throws Exception {
protected void toPath(InputStream fromStream, String toPath) throws Exception {
try (
GzipCompressorInputStream gzipInputStream = new GzipCompressorInputStream(nonClosing(fromStream));
TarArchiveInputStream tarInputStream = new TarArchiveInputStream(gzipInputStream)