Compare commits

...

2 Commits

Author SHA1 Message Date
0cf2aba878 Merge pull request 'v0.0.4' (#7) from dev into master
Reviewed-on: #7
2026-04-07 08:45:18 +00:00
Timi
01c21c7aa0 v0.0.4
Some checks failed
CI/CD / build-deploy (pull_request) Failing after 12s
2026-04-07 16:44:18 +08:00
3 changed files with 15 additions and 9 deletions

View File

@@ -46,10 +46,10 @@ public class GZipCompressor extends Compressor<GZipCompressor> {
List<File> files = IO.listFile(fromFile);
String basePath = files.getFirst().getParentFile().getAbsolutePath();
initByteProgress(IO.calcSize(fromFile));
try (
GzipCompressorOutputStream gzipOutputStream = new GzipCompressorOutputStream(new BufferedOutputStream(nonClosing(toStream)));
TarArchiveOutputStream tarOutputStream = new TarArchiveOutputStream(gzipOutputStream)
) {
TarArchiveOutputStream tarOutputStream = null;
try {
tarOutputStream = new TarArchiveOutputStream(gzipOutputStream);
for (File sourceFile : files) {
String name = sourceFile.getAbsolutePath().substring(basePath.length() + 1);
TarArchiveEntry tarEntry = new TarArchiveEntry(sourceFile, normalizeEntryName(name));
@@ -61,9 +61,13 @@ public class GZipCompressor extends Compressor<GZipCompressor> {
handleFile(sourceFile);
}
tarOutputStream.finish();
gzipOutputStream.finish();
finishProgress();
} finally {
if (tarOutputStream != null) {
tarOutputStream.close();
} else {
gzipOutputStream.close();
}
resetProgress();
}
}

View File

@@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@@ -52,8 +53,8 @@ public class GzipTest {
@Test
public void testCompressToStream() throws Exception {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
CompressType.GZIP.ofCompress("testSrc").toStream(outputStream);
try (OutputStream os = IO.getOutputStream(IO.file("testOut/test.tar.gz"))) {
CompressType.GZIP.ofCompress("testSrc").toStream(os);
}
}

View File

@@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@@ -52,8 +53,8 @@ public class TarTest {
@Test
public void testCompressToStream() throws Exception {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
CompressType.TAR.ofCompress("testSrc").toStream(outputStream);
try (OutputStream os = IO.getOutputStream(IO.file("testOut/test.tar"))) {
CompressType.TAR.ofCompress("testSrc").toStream(os);
}
}