7#include "../container/container.hpp"
9#include "../parser/parser.hpp"
10#include "../macros.hpp"
15hi_export_module(hikogui.codec.gzip);
17hi_export
namespace hi {
inline namespace v1 {
30[[nodiscard]]
inline bstring gzip_decompress_member(std::span<std::byte const> bytes,
std::size_t &offset,
std::size_t max_size)
32 auto const header = make_placement_ptr<gzip_member_header>(bytes, offset);
34 hi_check(header->ID1 == 31,
"GZIP Member header ID1 must be 31");
35 hi_check(header->ID2 == 139,
"GZIP Member header ID2 must be 139");
36 hi_check(header->CM == 8,
"GZIP Member header CM must be 8");
37 hi_check((header->FLG & 0xe0) == 0,
"GZIP Member header FLG reserved bits must be 0");
38 hi_check(header->XFL == 2 or header->XFL == 4,
"GZIP Member header XFL must be 2 or 4");
39 [[maybe_unused]]
auto const FTEXT = to_bool(header->FLG & 1);
40 auto const FHCRC = to_bool(header->FLG & 2);
41 auto const FEXTRA = to_bool(header->FLG & 4);
42 auto const FNAME = to_bool(header->FLG & 8);
43 auto const FCOMMENT = to_bool(header->FLG & 16);
46 auto const XLEN = **make_placement_ptr<little_uint16_buf_t>(bytes, offset);
53 hi_check(offset < bytes.size(),
"GZIP Member header FNAME reading beyond end of buffer");
55 }
while (c != std::byte{0});
61 hi_check(offset < bytes.size(),
"GZIP Member header FCOMMENT reading beyond end of buffer");
63 }
while (c != std::byte{0});
67 [[maybe_unused]]
auto const CRC16 = make_placement_ptr<little_uint16_buf_t>(bytes, offset);
70 auto r =
inflate(bytes, offset, max_size);
72 [[maybe_unused]]
auto CRC32 = **make_placement_ptr<little_uint32_buf_t>(bytes, offset);
73 [[maybe_unused]]
auto ISIZE = **make_placement_ptr<little_uint32_buf_t>(bytes, offset);
76 ISIZE == (size(r) & 0xffffffff),
77 "GZIP Member header ISIZE must be same as the lower 32 bits of the inflated size.");
83hi_export [[nodiscard]]
inline bstring gzip_decompress(std::span<std::byte const> bytes,
std::size_t max_size)
88 while (offset < bytes.size()) {
89 auto member = detail::gzip_decompress_member(bytes, offset, max_size);
90 max_size -= member.size();
97hi_export [[nodiscard]]
inline bstring gzip_decompress(std::filesystem::path
const &path,
std::size_t max_size = 0x01000000)
99 return gzip_decompress(as_span<std::byte const>(file_view{path}), max_size);
The HikoGUI namespace.
Definition array_generic.hpp:20
hi_export bstring inflate(std::span< std::byte const > bytes, std::size_t &offset, std::size_t max_size=0x0100 '0000)
Inflate compressed data using the deflate algorithm bytes should include at least 32 bit of trailer,...
Definition inflate.hpp:358
DOXYGEN BUG.
Definition algorithm_misc.hpp:20