14 if (input.size() > std::numeric_limits<
decltype(s.avail_in)>::max()) {
16 "Error while decompressing: input file too big");
18 auto inputLen =
static_cast<decltype(s.avail_in)
>(input.size());
23 s.next_in =
const_cast<uint8_t*
>(input.data());
24 s.avail_in = inputLen;
42 if (s.avail_in <= 0) {
44 "Error while decompressing: unexpected end of file.");
47 return *(s.next_in++);
70 repeat(len, [&] { result.push_back(narrow_cast<char>(
getByte())); });
77 while (
auto c = narrow_cast<char>(
getByte())) {
85 if (
int err = inflateInit2(&s, -MAX_WBITS);
88 "Error initializing inflate struct: ", zError(err));
92 size_t outSize = sizeHint;
94 s.avail_out = uInt(outSize);
96 s.next_out = output.
data() + s.total_out;
98 if (err == Z_STREAM_END) {
102 throw FileException(
"Error decompressing gzip: ", zError(err));
104 auto oldSize = outSize;
105 outSize = oldSize * 2;
107 s.avail_out = uInt(outSize - oldSize);
111 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)
MemBuffer< uint8_t > inflate(size_t sizeHint=65536)
ZlibInflate(std::span< const uint8_t > input)
This file implemented 3 utility functions:
constexpr void repeat(T n, Op op)
Repeat the given operation 'op' 'n' times.