From 415e9b82aeb209de6339e19f06fab40a00866d4e Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Wed, 9 Jun 2021 10:16:14 +0200 Subject: [PATCH] Use maximum compression instead of the default one Context: https://github.com/xamarin/xamarin-android/pull/5971#issuecomment-857279796 Also, attempt to tweak `zlib-ng` to use the best compression possible, by sacrificing speed. --- CMakeLists.txt | 1 + LibZipSharp.props | 2 +- LibZipSharp/Xamarin.Tools.Zip/ZipArchive.cs | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 52cec583..b54a8ae7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ endif() # set(ZLIB_COMPAT ON CACHE BOOL "Build zlib-ng for compatibility with zlib" FORCE) set(ZLIB_ENABLE_TESTS OFF CACHE BOOL "Do not build zlib-ng tests" FORCE) +set(WITH_NEW_STRATEGIES OFF CACHE BOOL "Disable faster, but with worse compression, deflate strategies" FORCE) # # Read product version diff --git a/LibZipSharp.props b/LibZipSharp.props index de6683ba..58c72535 100644 --- a/LibZipSharp.props +++ b/LibZipSharp.props @@ -1,6 +1,6 @@ - <_LibZipSharpNugetVersion>2.0.0-alpha4 + <_LibZipSharpNugetVersion>2.0.0-alpha5 <_NativeBuildDir>$(MSBuildThisFileDirectory)lzsbuild <_ExternalDir>$(MSBuildThisFileDirectory)external <_MonoPosixNugetVersion>7.0.0-alpha8.21302.6 diff --git a/LibZipSharp/Xamarin.Tools.Zip/ZipArchive.cs b/LibZipSharp/Xamarin.Tools.Zip/ZipArchive.cs index cd3088be..8d13cd53 100644 --- a/LibZipSharp/Xamarin.Tools.Zip/ZipArchive.cs +++ b/LibZipSharp/Xamarin.Tools.Zip/ZipArchive.cs @@ -329,7 +329,7 @@ public ZipEntry AddStream (Stream stream, string archivePath, EntryPermissions p long index = Native.zip_file_add (archive, destPath, source, overwriteExisting ? OperationFlags.Overwrite : OperationFlags.None); if (index < 0) throw GetErrorException (); - if (Native.zip_set_file_compression (archive, (ulong)index, compressionMethod, 0) < 0) + if (Native.zip_set_file_compression (archive, (ulong)index, compressionMethod, 9) < 0) throw GetErrorException (); if (permissions == EntryPermissions.Default) permissions = DefaultFilePermissions; @@ -410,7 +410,7 @@ public ZipEntry AddFile (string sourcePath, string archivePath = null, long index = PlatformServices.Instance.StoreSpecialFile (this, sourcePath, archivePath, out compressionMethod); if (index < 0) throw GetErrorException (); - if (Native.zip_set_file_compression (archive, (ulong)index, isDir ? CompressionMethod.Store : compressionMethod, 0) < 0) + if (Native.zip_set_file_compression (archive, (ulong)index, isDir ? CompressionMethod.Store : compressionMethod, 9) < 0) throw GetErrorException (); PlatformServices.Instance.SetEntryPermissions (this, sourcePath, (ulong)index, permissions); ZipEntry entry = ReadEntry ((ulong)index);