Commit 635df78f authored by Alexey Ivanov's avatar Alexey Ivanov 🐢 Committed by Elvis Angelaccio

libzipplugin: add support for zstd compression

PKWARE added zstd compression method to zip specification,
originally was pushed and supported only by WinZip Pro.

Compression level limited by 9 (libzip limitation) but zstd itself supports up to 22
(without using --ultra methods), see https://github.com/nih-at/libzip/issues/214

But ark doesn't support different compression levels for different compression methods either.

See also:
https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
93 - Zstandard (zstd) Compression

!15
parent 3119dac1
include(CheckSymbolExists)
include_directories(${LibZip_INCLUDE_DIRS})
set(SUPPORTED_LIBZIP_MIMETYPES "application/zip;")
......@@ -15,6 +17,12 @@ ecm_qt_declare_logging_category(kerfuffle_libzip_SRCS
# double-quotes of the last mime must NOT be escaped.
set(SUPPORTED_MIMETYPES "application/zip")
# TODO: replace with version-based check once there is a new libzip release with zstd support
check_symbol_exists(ZIP_CM_ZSTD "zip.h" HAVE_ZIP_CM_ZSTD)
if (HAVE_ZIP_CM_ZSTD)
set(ZIP_CM_ZSTD_JSON_LINE "\"Zstd\": \"Zstd\",")
endif()
find_package(ZLIB REQUIRED)
set_package_properties(ZLIB PROPERTIES
URL "https://www.zlib.net/"
......
......@@ -92,6 +92,7 @@
"CompressionMethodDefault": "Default",
"CompressionMethods": {
"BZip2": "BZip2",
@ZIP_CM_ZSTD_JSON_LINE@
"Default": "Default",
"Deflate": "Deflate",
"Store": "Store"
......
......@@ -256,6 +256,10 @@ bool LibzipPlugin::writeEntry(zip_t *archive, const QString &file, const Archive
compMethod = ZIP_CM_DEFLATE;
} else if (options.compressionMethod() == QLatin1String("BZip2")) {
compMethod = ZIP_CM_BZIP2;
#ifdef ZIP_CM_ZSTD
} else if (options.compressionMethod() == QLatin1String("Zstd")) {
compMethod = ZIP_CM_ZSTD;
#endif
} else if (options.compressionMethod() == QLatin1String("Store")) {
compMethod = ZIP_CM_STORE;
}
......@@ -322,6 +326,12 @@ bool LibzipPlugin::emitEntryForIndex(zip_t *archive, qlonglong index)
e->setProperty("method", QStringLiteral("BZip2"));
Q_EMIT compressionMethodFound(QStringLiteral("BZip2"));
break;
#ifdef ZIP_CM_ZSTD
case ZIP_CM_ZSTD:
e->setProperty("method", QStringLiteral("Zstd"));
Q_EMIT compressionMethodFound(QStringLiteral("Zstd"));
break;
#endif
case ZIP_CM_LZMA:
e->setProperty("method", QStringLiteral("LZMA"));
Q_EMIT compressionMethodFound(QStringLiteral("LZMA"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment