12 if (input.size() > std::numeric_limits<
decltype(s.avail_in)>::max()) {
14 "Error while decompressing: input file too big");
16 auto inputLen =
static_cast<decltype(s.avail_in)
>(input.size());
21 s.next_in =
const_cast<uint8_t*
>(input.data());
22 s.avail_in = inputLen;
40 if (s.avail_in <= 0) {
42 "Error while decompressing: unexpected end of file.");
45 return *(s.next_in++);
68 repeat(len, [&] { result.push_back(narrow_cast<char>(
getByte())); });
75 while (
auto c = narrow_cast<char>(
getByte())) {
83 if (
int err = inflateInit2(&s, -MAX_WBITS);
86 "Error initializing inflate struct: ", zError(err));
90 size_t outSize = sizeHint;
92 s.avail_out = uInt(outSize);
94 s.next_out = output.
data() + s.total_out;
96 if (err == Z_STREAM_END) {
100 throw FileException(
"Error decompressing gzip: ", zError(err));
102 auto oldSize = outSize;
103 outSize = oldSize * 2;
105 s.avail_out = uInt(outSize - oldSize);
109 output.
resize(s.total_out);
This class manages the lifetime of a block of memory.
void resize(size_t size)
Grow or shrink the memory block.
const T * data() const
Returns pointer to the start of the memory buffer.
std::string getString(size_t len)
ZlibInflate(std::span< const uint8_t > input)
size_t inflate(MemBuffer< uint8_t > &output, size_t sizeHint=65536)
This file implemented 3 utility functions:
constexpr void repeat(T n, Op op)
Repeat the given operation 'op' 'n' times.