diff --git a/src/docs/changes/README.md b/src/docs/changes/README.md index a58a1f91d..5fb6e527a 100644 --- a/src/docs/changes/README.md +++ b/src/docs/changes/README.md @@ -3,6 +3,9 @@ ## [Unreleased] +**Changed** + +- Use `BufferedOutputStream` when writing the Zip file to improve performance. ([#1579](https://github.com/GradleUp/shadow/pull/1579)) ## [v8.3.8] (2025-07-01) diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DefaultZipCompressor.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DefaultZipCompressor.groovy index 829ab294c..1e6dfa8b0 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DefaultZipCompressor.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DefaultZipCompressor.groovy @@ -30,7 +30,10 @@ class DefaultZipCompressor implements ZipCompressor { @Override ZipOutputStream createArchiveOutputStream(File destination) { try { - ZipOutputStream zipOutputStream = new ZipOutputStream(destination) + ZipOutputStream zipOutputStream = entryCompressionMethod == ZipOutputStream.STORED ? + new ZipOutputStream(destination) : + // It is not possible to do this with STORED entries as the implementation requires a RandomAccessFile to update the CRC after write. + new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(destination))) zipOutputStream.setUseZip64(zip64Mode) zipOutputStream.setMethod(entryCompressionMethod) return zipOutputStream