diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-01-23 16:31:48 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-02-04 10:49:07 +0100 |
commit | 272fa8935ed1e97a7c8a5e6cbd44bb47ac7dc00b (patch) | |
tree | 50b5747dd57680acadb4ab45ad52e075553ec11e /src/mbgl/util/compression.cpp | |
parent | fbe30e04c48353a9fdd14151728e27ffe168c9ca (diff) | |
download | qtlocation-mapboxgl-272fa8935ed1e97a7c8a5e6cbd44bb47ac7dc00b.tar.gz |
make storage lib separate so we can build without storage libs
Diffstat (limited to 'src/mbgl/util/compression.cpp')
-rw-r--r-- | src/mbgl/util/compression.cpp | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/src/mbgl/util/compression.cpp b/src/mbgl/util/compression.cpp deleted file mode 100644 index d6d6370546..0000000000 --- a/src/mbgl/util/compression.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include <mbgl/util/compression.hpp> - -#include <zlib.h> - -#include <cstring> -#include <stdexcept> - -namespace mbgl { -namespace util { - -std::string compress(const std::string &raw) { - z_stream deflate_stream; - memset(&deflate_stream, 0, sizeof(deflate_stream)); - - // TODO: reuse z_streams - if (deflateInit(&deflate_stream, Z_DEFAULT_COMPRESSION) != Z_OK) { - throw std::runtime_error("failed to initialize deflate"); - } - - deflate_stream.next_in = (Bytef *)raw.data(); - deflate_stream.avail_in = uInt(raw.size()); - - std::string result; - char out[16384]; - - int code; - do { - deflate_stream.next_out = reinterpret_cast<Bytef *>(out); - deflate_stream.avail_out = sizeof(out); - code = deflate(&deflate_stream, Z_FINISH); - if (result.size() < deflate_stream.total_out) { - // append the block to the output string - result.append(out, deflate_stream.total_out - result.size()); - } - } while (code == Z_OK); - - deflateEnd(&deflate_stream); - - if (code != Z_STREAM_END) { - throw std::runtime_error(deflate_stream.msg); - } - - return result; -} - -std::string decompress(const std::string &raw) { - z_stream inflate_stream; - memset(&inflate_stream, 0, sizeof(inflate_stream)); - - // TODO: reuse z_streams - if (inflateInit(&inflate_stream) != Z_OK) { - throw std::runtime_error("failed to initialize inflate"); - } - - inflate_stream.next_in = (Bytef *)raw.data(); - inflate_stream.avail_in = uInt(raw.size()); - - std::string result; - char out[15384]; - - int code; - do { - inflate_stream.next_out = reinterpret_cast<Bytef *>(out); - inflate_stream.avail_out = sizeof(out); - code = inflate(&inflate_stream, 0); - // result.append(out, sizeof(out) - inflate_stream.avail_out); - if (result.size() < inflate_stream.total_out) { - result.append(out, inflate_stream.total_out - result.size()); - } - } while (code == Z_OK); - - inflateEnd(&inflate_stream); - - if (code != Z_STREAM_END) { - throw std::runtime_error(inflate_stream.msg); - } - - return result; -} -} -} |