Skip to content

Commit 3fecd8d

Browse files
author
Dane Springmeyer
committed
template to avoid dep on std::string + ignore old world cast inside zlib macros
1 parent 82dfdb3 commit 3fecd8d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

include/gzip/compress.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// zlib
44
#include <zlib.h>
5+
56
// std
67
#include <limits>
78
#include <stdexcept>
@@ -25,7 +26,8 @@ class Compressor
2526
{
2627
}
2728

28-
void compress(std::string& output,
29+
template <typename InputType>
30+
void compress(InputType & output,
2931
const char* data,
3032
std::size_t size) const
3133
{
@@ -65,10 +67,13 @@ class Compressor
6567
// with a default value of 8 for mem_level and our window_bits of 15
6668
// this is 128Kb
6769

70+
#pragma GCC diagnostic push
71+
#pragma GCC diagnostic ignored "-Wold-style-cast"
6872
if (deflateInit2(&deflate_s, level_, Z_DEFLATED, window_bits, mem_level, strategy_) != Z_OK)
6973
{
7074
throw std::runtime_error("deflate init failed");
7175
}
76+
#pragma GCC diagnostic pop
7277

7378
deflate_s.next_in = reinterpret_cast<z_const Bytef*>(data);
7479
deflate_s.avail_in = static_cast<unsigned int>(size);

include/gzip/decompress.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// zlib
44
#include <zlib.h>
5+
56
// std
67
#include <limits>
78
#include <stdexcept>
@@ -19,7 +20,8 @@ class Decompressor
1920
{
2021
}
2122

22-
void decompress(std::string& output,
23+
template <typename OutputType>
24+
void decompress(OutputType & output,
2325
const char* data,
2426
std::size_t size) const
2527
{
@@ -41,10 +43,13 @@ class Decompressor
4143
// (8 to 15) + 32 to automatically detect gzip/zlib header
4244
constexpr int window_bits = 15 + 32; // auto with windowbits of 15
4345

46+
#pragma GCC diagnostic push
47+
#pragma GCC diagnostic ignored "-Wold-style-cast"
4448
if (inflateInit2(&inflate_s, window_bits) != Z_OK)
4549
{
4650
throw std::runtime_error("inflate init failed");
4751
}
52+
#pragma GCC diagnostic pop
4853
inflate_s.next_in = reinterpret_cast<z_const Bytef*>(data);
4954

5055
#ifdef DEBUG

0 commit comments

Comments
 (0)