From 354c83f314aeab86e49514bffca16efb92d48216 Mon Sep 17 00:00:00 2001 From: szymon Date: Sun, 10 Sep 2023 00:21:34 +0200 Subject: [PATCH] repaired #130. --- .../create/compressors/ZipCompressor.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/szum123321/textile_backup/core/create/compressors/ZipCompressor.java b/src/main/java/net/szum123321/textile_backup/core/create/compressors/ZipCompressor.java index a1b224b..ec4d062 100644 --- a/src/main/java/net/szum123321/textile_backup/core/create/compressors/ZipCompressor.java +++ b/src/main/java/net/szum123321/textile_backup/core/create/compressors/ZipCompressor.java @@ -61,8 +61,20 @@ public class ZipCompressor extends AbstractCompressor { if(input.getPath().isEmpty()) { entry = new ZipArchiveEntry(input.getName()); + + //It's basically just + byte[] buff = new byte[(int)input.size()]; + int len = input.getInputStream().read(buff); + Checksum sum = new CRC32(); + sum.update(buff, 0, len); + entry.setCrc(sum.getValue()); + entry.setMethod(ZipEntry.STORED); entry.setSize(input.size()); + + ((ZipArchiveOutputStream)arc).putArchiveEntry(entry); + + arc.write(buff, 0, len); } else { Path file = input.getPath().get(); entry = (ZipArchiveEntry) ((ZipArchiveOutputStream) arc).createArchiveEntry(file, input.getName()); @@ -72,12 +84,12 @@ public class ZipCompressor extends AbstractCompressor { entry.setCompressedSize(Files.size(file)); entry.setCrc(getCRC(file)); } else entry.setMethod(ZipEntry.DEFLATED); + + ((ZipArchiveOutputStream)arc).putArchiveEntry(entry); + + IOUtils.copy(fileInputStream, arc); } - ((ZipArchiveOutputStream)arc).putArchiveEntry(entry); - - IOUtils.copy(fileInputStream, arc); - ((ZipArchiveOutputStream)arc).closeArchiveEntry(); } }