expose callback-based reader to stream archives from a custom source

Open
#435 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
c
Domain
backend

Research direction

Start with the public reader API and the reader initialization paths in zip.c, then trace how mz_zip_archive.m_pRead and m_pIO_opaque are set and used. The issue proposes a callback signature and an additional open method, but names no files or tests; identify the public header and relevant tests before estimating the change. Done means callers can read an archive through their callback without keeping the full compressed archive in memory.

Written by the indexing model from the issue text.

Description

change request enhancement help wanted question under discussion

The public reader API forces a choice between reading from a path/FILE* or copying the entire compressed archive into RAM. There is no way to open an archive for reading backed by a custom data source (a caller-provided read callback). I'd like a public entry point that lets miniz pull compressed bytes on demand through my own callback.

I'm integrating zip into an engine that abstracts all I/O behind its own stream interface (not FILE*, and not necessarily a real filesystem path - resources can live inside other containers). Today my only option is:

zip_stream_open(buf, size, 0, 'r'); // requires the full archive in memory

which keeps the whole compressed archive resident for the archive's entire lifetime. For large archives this is a significant and unnecessary memory cost.

miniz already streams internally - mz_zip_reader_init* only parses the central directory up front, and entry data is pulled on demand via mz_zip_archive.m_pRead / m_pIO_opaque in 64 KB chunks. But because struct zip_t / mz_zip_archive are opaque outside zip.c, callers can't set m_pRead themselves. The streaming machinery exists; it just isn't exposed.

A read callback with the same shape as mz_file_read_func could be added:

typedef size_t (*zip_read_callback_t)(void *opaque, uint64_t offset,
                                      void *buf, size_t n);

and wired into an additional _open method.

Dominant language
C
Stars
1.6k
Forks
308
Avg merge
14h 22m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from kuba--/zip

All issues in kuba--/zip

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.