Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
gzip_document.hpp
1// Copyright (c) 2026 ttldtor.
2// SPDX-License-Identifier: BSL-1.0
3#pragma once
4
5#include <portals/document_source.hpp>
6#include <type_traits>
7
8namespace portals {
20
24// NOLINTNEXTLINE(readability-identifier-naming): Required std::error_code ADL customization spelling.
25std::error_code make_error_code(GzipError error) noexcept;
26
29 static constexpr std::size_t MAX_CHECKPOINTS = 64;
30 std::size_t compressedBlockBytes{64 * 1024};
31 std::size_t inflateOutputBytes{32 * 1024};
32 std::uint64_t checkpointStrideBytes{4 * 1024 * 1024};
33 std::size_t maxCheckpoints{8};
34 std::size_t replayBytes{64 * 1024};
35 std::size_t maxInflateBytes{512 * 1024};
36 std::size_t maxHeaderBytes{1024 * 1024};
37};
38
55class GzipDocumentProvider final : public ByteDocumentProvider {
56public:
63 static std::expected<std::shared_ptr<GzipDocumentProvider>, DocumentError>
64 create(std::shared_ptr<ByteDocumentProvider> compressed, std::shared_ptr<SourceBudget> budget,
65 GzipDocumentOptions options = {});
66
68 ByteDocumentCapabilities capabilities() const noexcept override;
72 std::size_t pinnedBudgetBytes(const SourceBudget &root) const noexcept override;
76 bool tryReleaseOptionalStorage() noexcept override;
80 std::expected<ByteDocumentMetadata, DocumentError> metadata(std::stop_token stop) override;
85 std::expected<ByteDocumentMetadata, DocumentError> discoverExtent(std::stop_token stop) override;
91 std::expected<ByteReadResult, DocumentError> read(const ByteReadCommand &command, std::span<std::byte> destination,
92 std::stop_token stop) override;
93
94private:
95 struct State;
96 explicit GzipDocumentProvider(std::unique_ptr<State> state);
97 std::unique_ptr<State> state_;
98};
99} // namespace portals
100
102template <> struct std::is_error_code_enum<portals::GzipError> : std::true_type {};
103
Read-only worker provider; callers serialize operations using the existing executor....
Definition document_source.hpp:88
~GzipDocumentProvider() override
Release all states before their allocator/root owners.
std::expected< ByteDocumentMetadata, DocumentError > metadata(std::stop_token stop) override
std::size_t pinnedBudgetBytes(const SourceBudget &root) const noexcept override
ByteDocumentCapabilities capabilities() const noexcept override
std::expected< ByteDocumentMetadata, DocumentError > discoverExtent(std::stop_token stop) override
static std::expected< std::shared_ptr< GzipDocumentProvider >, DocumentError > create(std::shared_ptr< ByteDocumentProvider > compressed, std::shared_ptr< SourceBudget > budget, GzipDocumentOptions options={})
std::expected< ByteReadResult, DocumentError > read(const ByteReadCommand &command, std::span< std::byte > destination, std::stop_token stop) override
bool tryReleaseOptionalStorage() noexcept override
Thread-safe credit ledger; final page/worker release may happen on any thread.
Definition source_budget.hpp:119
Public Portals API.
Definition action.hpp:8
GzipError
Gzip cause carried in DocumentError::native; implicitly convertible to std::error_code.
Definition gzip_document.hpp:10
@ HEADER_LIMIT
The configured compressed header limit was exceeded.
Definition gzip_document.hpp:17
@ CHECKSUM_MISMATCH
A member or header checksum did not match.
Definition gzip_document.hpp:13
@ INVALID_HEADER
Input does not start with a supported gzip header.
Definition gzip_document.hpp:11
@ INFLATE_LIMIT
The configured aggregate live inflater allocation limit was exceeded.
Definition gzip_document.hpp:18
@ SIZE_MISMATCH
A member's modulo-2^32 size check did not match.
Definition gzip_document.hpp:14
@ TRAILING_DATA
Bytes after a complete member are not another gzip member.
Definition gzip_document.hpp:16
@ TRUNCATED
Physical EOF arrived before the complete member trailer.
Definition gzip_document.hpp:15
@ CORRUPT_DATA
Invalid compressed data.
Definition gzip_document.hpp:12
std::error_code make_error_code(GzipError error) noexcept
Capabilities captured without I/O during cold source creation.
Definition document_source.hpp:31
Worker-observed provider metadata.
Definition document_source.hpp:38
Exact provider request; destination size bounds the byte window.
Definition document_source.hpp:51
Short reads alone never imply EOF.
Definition document_source.hpp:57
Failure with an optional native provider cause, preserved by source operations.
Definition document_source.hpp:13
Fixed RAM and replay policy; limits do not restrict logical document size.
Definition gzip_document.hpp:28
std::size_t replayBytes
Bounded logical byte replay ring; zero disables it.
Definition gzip_document.hpp:34
static constexpr std::size_t MAX_CHECKPOINTS
Supported bound for nonblocking optional-cache retirement.
Definition gzip_document.hpp:29
std::size_t inflateOutputBytes
Positive output quantum; cancellation is checked between calls.
Definition gzip_document.hpp:31
std::uint64_t checkpointStrideBytes
Positive logical spacing for optional snapshots.
Definition gzip_document.hpp:32
std::size_t maxCheckpoints
Live restart snapshots, from zero (disabled) through MAX_CHECKPOINTS.
Definition gzip_document.hpp:33
std::size_t compressedBlockBytes
Positive input quantum, at most64KiB.
Definition gzip_document.hpp:30
std::size_t maxHeaderBytes
Positive compressed-byte cap for each member header.
Definition gzip_document.hpp:36
std::size_t maxInflateBytes
Aggregate zlib allocation cap, including active and copied states.
Definition gzip_document.hpp:35