v0.0.1
Some checks failed
CI/CD / build-deploy (pull_request) Failing after 1m31s

This commit is contained in:
Timi
2026-04-01 14:09:24 +08:00
parent 47f1c9520e
commit afcc902cbf
20 changed files with 986 additions and 396 deletions

View File

@@ -6,56 +6,39 @@ import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
/**
* Tar 压缩器
*
* @author 夜雨
* @version 2024-06-30 19:48
*/
public class TarCompressor extends Compressor {
@Override
public void run(String fromPath, File toFile) throws Exception {
List<File> files = IO.listFile(new File(fromPath));
public void run(String fromPath, OutputStream toStream) throws Exception {
File fromFile = new File(fromPath);
List<File> files = IO.listFile(fromFile);
String basePath = files.getFirst().getParentFile().getAbsolutePath();
OutputStream os = IO.getOutputStream(toFile);
BufferedOutputStream byteOS = new BufferedOutputStream(os);
TarArchiveOutputStream tarOS = new TarArchiveOutputStream(byteOS);
TarArchiveEntry tarEntry;
for (int i = 0, total = files.size(); i < total; i++) {
String name = files.get(i).getAbsolutePath().substring(basePath.length() + 1);
tarEntry = new TarArchiveEntry(files.get(i), name.replaceAll("\\\\", "/"));
tarOS.putArchiveEntry(tarEntry);
tarOS.write(IO.toBytes(files.get(i)));
tarOS.closeArchiveEntry();
if (isPause) {
synchronized (pauseLock) {
pauseLock.wait();
initByteProgress(IO.calcSize(fromFile));
try (TarArchiveOutputStream tarOutputStream = new TarArchiveOutputStream(new BufferedOutputStream(nonClosing(toStream)))) {
for (File sourceFile : files) {
String name = sourceFile.getAbsolutePath().substring(basePath.length() + 1);
TarArchiveEntry tarEntry = new TarArchiveEntry(sourceFile, normalizeEntryName(name));
tarOutputStream.putArchiveEntry(tarEntry);
try (InputStream inputStream = IO.getInputStream(sourceFile)) {
transfer(inputStream, tarOutputStream);
}
tarOutputStream.closeArchiveEntry();
handleFile(sourceFile);
}
if (fileCallback != null) {
fileCallback.handler(toFile);
}
if (progressCallback != null) {
progressCallback.handler(1D * i / total);
}
if (isInterrupt) {
break;
}
}
tarOS.finish();
tarOS.close();
byteOS.flush();
byteOS.close();
os.flush();
os.close();
if (isInterrupt) {
IO.destroy(toFile);
tarOutputStream.finish();
finishProgress();
} finally {
resetProgress();
}
}
}