BZlibCompressionAlgorithm: Basic support for gzip format
This commit is contained in:
@@ -31,9 +31,14 @@ public:
|
||||
size_t BufferSize() const;
|
||||
void SetBufferSize(size_t size);
|
||||
|
||||
// TODO: Support setting the gzip header.
|
||||
bool IsGzipFormat() const;
|
||||
void SetGzipFormat(bool gzipFormat);
|
||||
|
||||
private:
|
||||
int32 fCompressionLevel;
|
||||
size_t fBufferSize;
|
||||
bool fGzipFormat;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,8 @@ BZlibCompressionParameters::BZlibCompressionParameters(
|
||||
:
|
||||
BCompressionParameters(),
|
||||
fCompressionLevel(compressionLevel),
|
||||
fBufferSize(kDefaultBufferSize)
|
||||
fBufferSize(kDefaultBufferSize),
|
||||
fGzipFormat(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -83,6 +84,20 @@ BZlibCompressionParameters::SetBufferSize(size_t size)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BZlibCompressionParameters::IsGzipFormat() const
|
||||
{
|
||||
return fGzipFormat;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BZlibCompressionParameters::SetGzipFormat(bool gzipFormat)
|
||||
{
|
||||
fGzipFormat = gzipFormat;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - BZlibDecompressionParameters
|
||||
|
||||
|
||||
@@ -127,10 +142,18 @@ struct BZlibCompressionAlgorithm::CompressionStrategy {
|
||||
static int Init(z_stream& stream,
|
||||
const BZlibCompressionParameters* parameters)
|
||||
{
|
||||
return deflateInit(&stream,
|
||||
parameters != NULL
|
||||
? parameters->CompressionLevel()
|
||||
: B_ZLIB_COMPRESSION_DEFAULT);
|
||||
int32 compressionLevel = B_ZLIB_COMPRESSION_DEFAULT;
|
||||
bool gzipFormat = false;
|
||||
if (parameters != NULL) {
|
||||
compressionLevel = parameters->CompressionLevel();
|
||||
gzipFormat = parameters->IsGzipFormat();
|
||||
}
|
||||
|
||||
return deflateInit2(&stream, compressionLevel,
|
||||
Z_DEFLATED,
|
||||
MAX_WBITS + (gzipFormat ? 16 : 0),
|
||||
MAX_MEM_LEVEL,
|
||||
Z_DEFAULT_STRATEGY);
|
||||
}
|
||||
|
||||
static void Uninit(z_stream& stream)
|
||||
@@ -159,7 +182,8 @@ struct BZlibCompressionAlgorithm::DecompressionStrategy {
|
||||
static int Init(z_stream& stream,
|
||||
const BZlibDecompressionParameters* /*parameters*/)
|
||||
{
|
||||
return inflateInit(&stream);
|
||||
// auto-detect zlib/gzip header
|
||||
return inflateInit2(&stream, 32 + MAX_WBITS);
|
||||
}
|
||||
|
||||
static void Uninit(z_stream& stream)
|
||||
|
||||
Reference in New Issue
Block a user