48static const char*
const s_tag =
"epub_entry";
66typedef enum : uint8_t {
76typedef enum : uint8_t {
87typedef enum : uint8_t {
114 return (mz_zip_archive*)storage;
140 int32_t idx = mz_zip_reader_locate_file(zip, full_path,
nullptr, 0U);
142 idx = mz_zip_reader_locate_file(zip, path,
nullptr, 0U);
173 if ((archive_ofs + (uint64_t)n) > (uint64_t)book->
zip_size) {
211 if (
memcmp(hdr, sig,
sizeof(sig)) != 0) {
214 const uint32_t fname =
217 const uint32_t extra =
220 *out_data_ofs = local_header_ofs + (uint64_t)
k_epub_ldh_size + (uint64_t)fname + (uint64_t)extra;
246 mz_zip_reader_extract_iter_state** out_iter,
247 uint64_t* out_uncomp)
255 mz_zip_archive_file_stat st;
256 if (mz_zip_reader_file_stat(zip, (mz_uint)idx, &st) == MZ_FALSE) {
263 mz_zip_reader_extract_iter_state* iter = mz_zip_reader_extract_iter_new(zip, (mz_uint)idx, 0U);
264 if (iter ==
nullptr) {
268 *out_uncomp = (uint64_t)st.m_uncomp_size;
295 uint64_t* out_data_ofs,
296 uint64_t* out_uncomp)
304 mz_zip_archive_file_stat st;
305 if (mz_zip_reader_file_stat(zip, (mz_uint)idx, &st) == MZ_FALSE) {
312 if (st.m_method != 0U) {
322 *out_uncomp = (uint64_t)st.m_uncomp_size;
339 (void)
memset(out_reader, 0,
sizeof(*out_reader));
344 mz_zip_reader_extract_iter_state* iter =
nullptr;
345 uint64_t uncomp = 0U;
350 out_reader->
iter = iter;
351 out_reader->
book = book;
352 out_reader->
total = uncomp;
353 out_reader->
done = (uncomp == 0U) ? 1U : 0U;
354 if (out_size !=
nullptr) {
366 if (reader->
iter ==
nullptr) {
372 if (reader->
done != 0U) {
376 mz_zip_reader_extract_iter_state* iter = (mz_zip_reader_extract_iter_state*)reader->
iter;
377 const size_t n = mz_zip_reader_extract_iter_read(iter, buf, cap);
395 if (reader->
iter ==
nullptr) {
398 mz_zip_reader_extract_iter_state* iter = (mz_zip_reader_extract_iter_state*)reader->
iter;
400 if (reader->
total > 0U) {
405 const mz_bool ok = mz_zip_reader_extract_iter_free(iter);
406 reader->
iter =
nullptr;
408 if (ok == MZ_FALSE) {
462 uint64_t data_ofs = 0U;
463 uint64_t uncomp = 0U;
468 if (offset >= uncomp) {
471 const uint64_t avail = uncomp - offset;
472 const size_t n = ((uint64_t)len > avail) ? (
size_t)avail : len;
EPUB (.epub) reader and chapter iterator for ra8-firmware.
@ k_epub_max_path_len
Max href length (incl.
bool priv_epub_book_not_ready(uint8_t in_use, uint8_t zip_archive_active)
Pure book-not-ready predicate.
void priv_epub_join_path(const char *dir, const char *name, char *dst, size_t cap)
Concatenate dir + name into dst, NUL-terminated.
static ra8_err_t internal_open_iter(epub_book_t *book, const char *path, mz_zip_reader_extract_iter_state **out_iter, uint64_t *out_uncomp)
Locate + stat an entry and start a miniz extract-iterator over it.
static ra8_err_t internal_locate(mz_zip_archive *zip, epub_book_t *book, const char *path, int32_t *out_idx)
Locate an entry by OPF-prefixed path, falling back to the bare path.
epub_ldh_t
Local-file-header size + the two variable-length field-length offsets.
@ k_epub_ldh_size
Fixed local-header length, bytes.
@ k_epub_ldh_fname_len_ofs
uint16 file-name length field offset.
@ k_epub_ldh_extra_len_ofs
uint16 extra-field length field offset.
epub_ldh_sig_t
Local-file-header signature bytes (little-endian 0x04034b50).
@ k_epub_ldh_sig_0
Signature byte 0 ('P').
@ k_epub_ldh_sig_2
Signature byte 2.
@ k_epub_ldh_sig_1
Signature byte 1 ('K').
@ k_epub_ldh_sig_3
Signature byte 3.
static ra8_err_t internal_pread_null_ok(const epub_book_t *book, const char *path, const uint8_t *buf, const size_t *got)
Reject any NULL epub_entry_pread pointer argument.
ra8_err_t epub_entry_pread(epub_book_t *book, const char *path, uint64_t offset, uint8_t *buf, size_t len, size_t *got)
Positioned read of a stored (uncompressed) archive entry – windowed random access in bounded RAM (#23...
ra8_err_t epub_entry_read(epub_entry_reader_t *reader, uint8_t *buf, size_t cap, size_t *got)
Pull the next chunk of a streaming entry into a bounded caller buffer (#231).
static mz_zip_archive * internal_zip(epub_book_t *book)
Borrow the book's inline mz_zip_archive.
static ra8_err_t internal_stored_data_offset(epub_book_t *book, const char *path, uint64_t *out_data_ofs, uint64_t *out_uncomp)
Resolve a stored entry's archive data offset + uncompressed size.
epub_le_t
Little-endian byte shift + index constants for the header fields.
@ k_epub_le_lo
Low-order byte index.
@ k_epub_le_shift
High-byte left shift.
@ k_epub_le_hi
High-order byte index.
static bool internal_data_offset(const uint8_t *hdr, uint64_t local_header_ofs, uint64_t *out_data_ofs)
Verify a 30-byte local header and return the entry's data offset.
ra8_err_t epub_entry_close(epub_entry_reader_t *reader)
Tear down a streaming-entry cursor and release its inflate state (#231).
static bool internal_backing_read(epub_book_t *book, uint64_t archive_ofs, uint8_t *buf, size_t n)
Read n absolute archive bytes off the book's backing (resident or streamed).
ra8_err_t epub_entry_open(epub_book_t *book, const char *path, epub_entry_reader_t *out_reader, uint64_t *out_size)
Begin a bounded-RAM streaming extraction of one archive entry (#231).
Iterative, bounded-RAM ZIP-entry extraction for the EPUB reader (#231).
Test-access surface for epub internal helpers (MC/DC).
ra8_err_t priv_epub_zip_guard_entry(const mz_zip_archive_file_stat *st)
Guard one ZIP entry's declared sizes against the policy.
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#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.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
@ k_ra8_err_validation_failed
Validation rule failed (caller-supplied invariant not satisfied).
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_not_found
Requested item not found (lookup / search missed).
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
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.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
size_t zip_size
Length of the EPUB blob.
epub_stream_media_t stream_media
Streamed media descriptor; {} for the resident path.
uint8_t zip_archive_storage[k_epub_zip_archive_bytes]
Zip archive storage.
uint8_t zip_archive_active
1 = mz_zip_reader_init succeeded.
uint8_t in_use
1 = open, 0 = closed.
char opf_dir[k_epub_max_path_len]
Directory portion of the OPF.
const uint8_t * zip_bytes
Pointer to the EPUB blob.
Forward streaming cursor over one ZIP entry – inflate in bounded RAM (#231).
uint64_t consumed
Bytes delivered to the caller so far.
uint8_t done
1 once EOF has been reached / reported.
epub_book_t * book
Owning book (archive + allocator); borrowed.
void * iter
Opaque mz_zip_reader_extract_iter_state*; NULL when closed.
uint64_t total
Entry uncompressed size, bytes.