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