Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Gorshenin <y@maps.me>2017-05-02 15:48:39 +0300
committerYuri Gorshenin <y@maps.me>2017-05-02 15:48:39 +0300
commit5c8c7b6260598aa1cc4754d7d6deb05dbd54e9ef (patch)
tree1a4af8a2aadc044bda12e41f6b3f3f126c6e14dd /coding/zlib.cpp
parentbaaddc479ae50f43ea330aa12babbc9bab3e57f1 (diff)
[coding] Added GZip support.
Diffstat (limited to 'coding/zlib.cpp')
-rw-r--r--coding/zlib.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/coding/zlib.cpp b/coding/zlib.cpp
index 78799f3d8f..9c6850cfb3 100644
--- a/coding/zlib.cpp
+++ b/coding/zlib.cpp
@@ -6,14 +6,15 @@ namespace coding
{
namespace
{
-int ToInt(ZLib::Level level)
+int ToInt(ZLib::Deflate::Level level)
{
+ using Level = ZLib::Deflate::Level;
switch (level)
{
- case ZLib::Level::NoCompression: return Z_NO_COMPRESSION;
- case ZLib::Level::BestSpeed: return Z_BEST_SPEED;
- case ZLib::Level::BestCompression: return Z_BEST_COMPRESSION;
- case ZLib::Level::DefaultCompression: return Z_DEFAULT_COMPRESSION;
+ case Level::NoCompression: return Z_NO_COMPRESSION;
+ case Level::BestSpeed: return Z_BEST_SPEED;
+ case Level::BestCompression: return Z_BEST_COMPRESSION;
+ case Level::DefaultCompression: return Z_DEFAULT_COMPRESSION;
}
}
} // namespace
@@ -50,10 +51,20 @@ bool ZLib::Processor::BufferIsFull() const
}
// ZLib::Deflate -----------------------------------------------------------------------------------
-ZLib::DeflateProcessor::DeflateProcessor(void const * data, size_t size, ZLib::Level level) noexcept
+ZLib::DeflateProcessor::DeflateProcessor(Deflate::Format format, Deflate::Level level,
+ void const * data, size_t size) noexcept
: Processor(data, size)
{
- int const ret = deflateInit(&m_stream, ToInt(level));
+ auto bits = MAX_WBITS;
+ switch (format)
+ {
+ case Deflate::Format::ZLib: break;
+ case Deflate::Format::GZip: bits = bits | 16; break;
+ }
+
+ int const ret =
+ deflateInit2(&m_stream, ToInt(level) /* level */, Z_DEFLATED /* method */,
+ bits /* windowBits */, 8 /* memLevel */, Z_DEFAULT_STRATEGY /* strategy */);
m_init = (ret == Z_OK);
}
@@ -70,10 +81,18 @@ int ZLib::DeflateProcessor::Process(int flush)
}
// ZLib::Inflate -----------------------------------------------------------------------------------
-ZLib::InflateProcessor::InflateProcessor(void const * data, size_t size) noexcept
+ZLib::InflateProcessor::InflateProcessor(Inflate::Format format, void const * data,
+ size_t size) noexcept
: Processor(data, size)
{
- int const ret = inflateInit(&m_stream);
+ auto bits = MAX_WBITS;
+ switch (format)
+ {
+ case Inflate::Format::ZLib: break;
+ case Inflate::Format::GZip: bits = bits | 16; break;
+ case Inflate::Format::Both: bits = bits | 32; break;
+ }
+ int const ret = inflateInit2(&m_stream, bits);
m_init = (ret == Z_OK);
}