Package Kit: add Zstd compression.

Change-Id: Idbdb7cf1bde659046a88ea69a76e3b5fc4cd7013
Reviewed-on: https://review.haiku-os.org/323
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Jérôme Duval
2018-08-11 23:10:00 +00:00
committed by waddlesplash
parent b8a38e2bc1
commit 81375d4fbb
8 changed files with 82 additions and 5 deletions
+2 -1
View File
@@ -98,7 +98,8 @@ enum BHPKGAttributeID {
// compression types
enum {
B_HPKG_COMPRESSION_NONE = 0,
B_HPKG_COMPRESSION_ZLIB = 1
B_HPKG_COMPRESSION_ZLIB = 1,
B_HPKG_COMPRESSION_ZSTD = 2
};
@@ -5,6 +5,17 @@ UseBuildFeatureHeaders zlib ;
UsePrivateKernelHeaders ;
UsePrivateHeaders package shared storage support ;
local zstdSources ;
local zstdKernelLib ;
if [ FIsBuildFeatureEnabled zstd ] {
zstdSources = ZstdCompressionAlgorithm.cpp ;
zstdKernelLib = kernel_libzstd.a ;
UseBuildFeatureHeaders zstd ;
Includes [ FGristFiles $(zstdSources) ]
: [ BuildFeatureAttribute zstd : headers ] ;
SubDirC++Flags -DZSTD_ENABLED ;
}
local subDirs =
indices
@@ -117,6 +128,7 @@ local storageKitSources =
local supportKitSources =
CompressionAlgorithm.cpp
ZlibCompressionAlgorithm.cpp
$(zstdSources)
;
KernelAddon packagefs
@@ -129,7 +141,7 @@ KernelAddon packagefs
$(storageKitSources)
$(supportKitSources)
: kernel_libz.a
: kernel_libz.a $(zstdKernelLib)
;
+10 -1
View File
@@ -39,6 +39,7 @@ command_create(int argc, const char* const* argv)
bool quiet = false;
bool verbose = false;
int32 compressionLevel = BPackageKit::BHPKG::B_HPKG_COMPRESSION_LEVEL_BEST;
int32 compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZLIB;
while (true) {
static struct option sLongOptions[] = {
@@ -49,7 +50,7 @@ command_create(int argc, const char* const* argv)
};
opterr = 0; // don't print errors
int c = getopt_long(argc, (char**)argv, "+b0123456789C:hi:I:qv",
int c = getopt_long(argc, (char**)argv, "+b0123456789C:hi:I:qvz",
sLongOptions, NULL);
if (c == -1)
break;
@@ -96,6 +97,10 @@ command_create(int argc, const char* const* argv)
verbose = true;
break;
case 'z':
compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZSTD;
break;
default:
print_usage_and_exit(true);
break;
@@ -123,6 +128,10 @@ command_create(int argc, const char* const* argv)
BPackageKit::BHPKG::B_HPKG_COMPRESSION_NONE);
}
if (compressionLevel == 0)
compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_NONE;
writerParameters.SetCompression(compression);
PackageWriterListener listener(verbose, quiet);
BPackageWriter packageWriter(&listener);
status_t result = packageWriter.Init(packageFileName, &writerParameters);
+10 -1
View File
@@ -45,6 +45,7 @@ command_recompress(int argc, const char* const* argv)
bool quiet = false;
bool verbose = false;
int32 compressionLevel = BPackageKit::BHPKG::B_HPKG_COMPRESSION_LEVEL_BEST;
int32 compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZLIB;
while (true) {
static struct option sLongOptions[] = {
@@ -55,7 +56,7 @@ command_recompress(int argc, const char* const* argv)
};
opterr = 0; // don't print errors
int c = getopt_long(argc, (char**)argv, "+0123456789:hqv",
int c = getopt_long(argc, (char**)argv, "+0123456789:hqvz",
sLongOptions, NULL);
if (c == -1)
break;
@@ -86,6 +87,10 @@ command_recompress(int argc, const char* const* argv)
verbose = true;
break;
case 'z':
compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_ZSTD;
break;
default:
print_usage_and_exit(true);
break;
@@ -124,6 +129,10 @@ command_recompress(int argc, const char* const* argv)
BPackageKit::BHPKG::B_HPKG_COMPRESSION_NONE);
}
if (compressionLevel == 0)
compression = BPackageKit::BHPKG::B_HPKG_COMPRESSION_NONE;
writerParameters.SetCompression(compression);
PackageWriterListener listener(verbose, quiet);
BPackageWriter packageWriter(&listener);
if (strcmp(outputPackageFileName, "-") == 0) {
+2
View File
@@ -50,6 +50,7 @@ static const char* kUsage =
"\n"
" -q - Be quiet (don't show any output except for errors).\n"
" -v - Be verbose (show more info about created package).\n"
" -z - Use Zstd compression.\n"
"\n"
" create [ <options> ] <package>\n"
" Creates package file <package> from contents of current directory.\n"
@@ -120,6 +121,7 @@ static const char* kUsage =
" Defaults to 9.\n"
" -q - Be quiet (don't show any output except for errors).\n"
" -v - Be verbose (show more info about created package).\n"
" -z - Use Zstd compression.\n"
"\n"
"Common Options:\n"
" -h, --help - Print this usage info.\n"
+3 -1
View File
@@ -62,7 +62,9 @@ local architectureObject ;
for architectureObject in [ MultiArchSubDirSetup ] {
on $(architectureObject) {
UseBuildFeatureHeaders curl ;
if [ FIsBuildFeatureEnabled zstd ] {
SubDirC++Flags -DZSTD_ENABLED ;
}
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg ] ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package hpkg v1 ] ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits package manager ] ;
+16
View File
@@ -20,6 +20,9 @@
#include <DataIO.h>
#include <ZlibCompressionAlgorithm.h>
#ifdef ZSTD_ENABLED
#include <ZstdCompressionAlgorithm.h>
#endif
#include <package/hpkg/HPKGDefsPrivate.h>
#include <package/hpkg/PackageFileHeapReader.h>
@@ -824,6 +827,19 @@ ReaderImplBase::InitHeapReader(uint32 compression, uint32 chunkSize,
return B_NO_MEMORY;
}
break;
#ifdef ZSTD_ENABLED
case B_HPKG_COMPRESSION_ZSTD:
decompressionAlgorithm = DecompressionAlgorithmOwner::Create(
new(std::nothrow) BZstdCompressionAlgorithm,
new(std::nothrow) BZstdDecompressionParameters);
decompressionAlgorithmReference.SetTo(decompressionAlgorithm, true);
if (decompressionAlgorithm == NULL
|| decompressionAlgorithm->algorithm == NULL
|| decompressionAlgorithm->parameters == NULL) {
return B_NO_MEMORY;
}
break;
#endif
default:
fErrorOutput->PrintError("Error: Invalid heap compression\n");
return B_BAD_DATA;
+26
View File
@@ -20,6 +20,9 @@
#include <AutoDeleter.h>
#include <ZlibCompressionAlgorithm.h>
#ifdef ZSTD_ENABLED
#include <ZstdCompressionAlgorithm.h>
#endif
#include <package/hpkg/DataReader.h>
#include <package/hpkg/ErrorOutput.h>
@@ -326,6 +329,29 @@ WriterImplBase::InitHeapReader(size_t headerSize)
throw std::bad_alloc();
}
break;
#ifdef ZSTD_ENABLED
case B_HPKG_COMPRESSION_ZSTD:
compressionAlgorithm = CompressionAlgorithmOwner::Create(
new(std::nothrow) BZstdCompressionAlgorithm,
new(std::nothrow) BZstdCompressionParameters(
fParameters.CompressionLevel()));
compressionAlgorithmReference.SetTo(compressionAlgorithm, true);
decompressionAlgorithm = DecompressionAlgorithmOwner::Create(
new(std::nothrow) BZstdCompressionAlgorithm,
new(std::nothrow) BZstdDecompressionParameters);
decompressionAlgorithmReference.SetTo(decompressionAlgorithm, true);
if (compressionAlgorithm == NULL
|| compressionAlgorithm->algorithm == NULL
|| compressionAlgorithm->parameters == NULL
|| decompressionAlgorithm == NULL
|| decompressionAlgorithm->algorithm == NULL
|| decompressionAlgorithm->parameters == NULL) {
throw std::bad_alloc();
}
break;
#endif
default:
fErrorOutput->PrintError("Error: Invalid heap compression\n");
return B_BAD_VALUE;