LibDEFLATE: Add GZip support

This allows compressing and decompressing with data using GZip headers
and footers
This commit is contained in:
2026-02-20 00:00:32 +02:00
parent 632787b142
commit 7c1b403e05
4 changed files with 125 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ namespace LibDEFLATE
{
Raw,
Zlib,
GZip,
};
}

View File

@@ -19,6 +19,25 @@ namespace LibDEFLATE
return (s2 << 16) | s1;
}
inline uint32_t calculate_crc32(BAN::ConstByteSpan data)
{
uint32_t crc32 = 0xFFFFFFFF;
uint32_t polynomial = 0xEDB88320;
for (size_t i = 0; i < data.size(); i++) {
crc32 ^= data[i];
for (size_t j = 0; j < 8; j++) {
if (crc32 & 1)
crc32 = (crc32 >> 1) ^ polynomial;
else
crc32 >>= 1;
}
}
return ~crc32;
}
inline constexpr uint16_t reverse_bits(uint16_t value, size_t count)
{
uint16_t reverse = 0;