44 "k_comic_zip_bytes too small for mz_zip_archive");
45static_assert(
alignof(mz_zip_archive) <=
alignof(max_align_t),
46 "mz_zip_archive alignment exceeds max_align_t");
53typedef enum : uint16_t {
75 return (mz_zip_archive*)storage;
103 if (sm->
read ==
nullptr) {
106 if (file_ofs >= sm->
size) {
109 const uint64_t avail = sm->
size - file_ofs;
110 const size_t want = ((uint64_t)n > avail) ? (
size_t)avail : n;
111 return sm->
read(sm->
ctx, (uint64_t)file_ofs, buf, want);
165 if (mz_zip_reader_is_file_a_directory(zip, i) != MZ_FALSE) {
169 (void)mz_zip_reader_get_filename(zip, i, nb, (mz_uint)
sizeof(nb));
170 nb[
sizeof(nb) - 1U] =
'\0';
172 for (; nl <
sizeof(nb); ++nl) {
173 if (nb[nl] ==
'\0') {
180 mz_zip_archive_file_stat st = {};
181 if (mz_zip_reader_file_stat(zip, i, &st) == MZ_FALSE) {
196 (uint64_t)st.m_uncomp_size,
212 (void)
memset(zip, 0,
sizeof(*zip));
218 zip->m_pIO_opaque = &c->
stream;
219 if (mz_zip_reader_init(zip, (mz_uint64)c->
size, 0U) == MZ_FALSE) {
224 const mz_uint num = mz_zip_reader_get_num_files(zip);
232 for (mz_uint i = 0U; i < num; ++i) {
253 if ((uint64_t)cap < p->raw_size) {
257 if (mz_zip_reader_extract_to_mem(zip, (mz_uint)p->
zip_index, buf, cap, 0U) == MZ_FALSE) {
bool priv_comic_is_page_name(const char *name, uint16_t len)
Whether an archive entry name is a decodable comic page image.
ra8_err_t priv_comic_page_add(comic_t *c, const char *name, uint16_t name_len, uint64_t raw_size, uint8_t extractable, uint8_t method, uint32_t zip_index, uint64_t data_off, uint64_t pack_size)
Append one image member to the resident page index.
Unified demand-paged reader for comic-book archives – CBZ (ZIP) and CBR (RAR).
@ k_comic_zip_bytes
Inline storage for miniz's mz_zip_archive.
cbz_limits_t
Per-entry name scratch size for the central-directory walk.
@ k_cbz_name_max
Longest entry name indexed (bytes, incl.
static const char *const s_tag_cbz
Log tag for CBZ-backend diagnostics.
static size_t internal_stream_read(void *opaque, mz_uint64 file_ofs, void *buf, size_t n)
miniz user-read trampoline – forward to the comic's seek+read backing.
static ra8_err_t internal_add_entry(comic_t *c, mz_zip_archive *zip, mz_uint i)
Index one central-directory entry if it is a decodable page image.
static mz_zip_archive * internal_zip(comic_t *c)
The comic's inline mz_zip_archive view.
ra8_err_t priv_comic_cbz_extract(comic_t *c, const comic_page_t *p, uint8_t *buf, size_t cap, size_t *got)
Extract one CBZ page's encoded image through the streaming ZIP reader.
ra8_err_t priv_comic_cbz_close(comic_t *c)
Tear down the CBZ backend's miniz reader.
static ra8_err_t internal_set_alloc(comic_t *c, mz_zip_archive *zip)
Route miniz allocations through this comic's private bounded arena.
ra8_err_t priv_comic_cbz_open(comic_t *c)
Open the CBZ (ZIP) backend: init the streaming miniz reader + page index.
Cross-TU seams between the comic facade and its CBZ / CBR backends.
Caller-owned bounded-arena allocator for miniz.
void epub_miniz_free(void *opaque, void *address)
miniz-compatible free (mz_free_func).
ra8_err_t epub_miniz_arena_init(epub_miniz_arena_t *arena, void *workspace, size_t workspace_bytes)
Initialise or reset a miniz arena over caller-owned storage.
void * epub_miniz_alloc(void *opaque, size_t items, size_t size)
miniz-compatible allocator (mz_alloc_func).
void * epub_miniz_realloc(void *opaque, void *address, size_t items, size_t size)
miniz-compatible realloc (mz_realloc_func).
void epub_miniz_arena_deinit(epub_miniz_arena_t *arena)
Invalidate an arena descriptor after miniz has released its blocks.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Unified decompression-limits policy: one bound set for every decoder.
ra8_decomp_limits_t ra8_decomp_limits_default(void)
The owner-approved default decompression policy.
ra8_err_t ra8_decomp_check_declared(const ra8_decomp_limits_t *limits, uint64_t comp_size, uint64_t out_size)
Header-level check of a member's declared sizes against a policy.
ra8_err_t ra8_decomp_zip_entry_preflight(ra8_decomp_read_fn read, void *ctx, uint64_t archive_size)
Reject an over-cap ZIP from its EOCD before directory allocation.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_err_validation_failed
Validation rule failed (caller-supplied invariant not satisfied).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_decomp_entries
Archive entry-count cap breached (ra8_decomp_limits_t).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
@ k_ra8_rar_method_store
Uncompressed: data area is the file bytes.
One entry in the resident, sorted page index.
uint64_t raw_size
Encoded image length in bytes (decoder input).
uint32_t zip_index
CBZ: miniz central-directory index.
Stable seek+read descriptor bound to the CBZ backend's miniz reader.
uint64_t size
Archive length in bytes.
void * ctx
Backing context.
comic_read_fn read
Backing reader (mirrors comic_t::read).
One open comic archive: backing, kind, page index, and backend state.
epub_miniz_arena_t miniz_arena
Per-comic allocator descriptor bound through miniz's opaque pointer.
uint8_t zip_active
1 = miniz reader is initialised (CBZ).
comic_stream_t stream
CBZ miniz I/O descriptor (stable addr).
uint8_t zip_storage[k_comic_zip_bytes]
Inline storage for miniz's mz_zip_archive (CBZ; no heap).
uint64_t size
Archive length in bytes.
epub_miniz_workspace_t miniz_workspace
Per-comic bounded allocator workspace (used only for CBZ).
uint8_t bytes[k_epub_miniz_pool_bytes]
Allocator backing bytes.
One decompression policy: the five resource bounds decoders enforce.
uint32_t max_entries
Per-archive enumerated-entry cap.