Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to seek within iterative decompression #275

Open
codecat opened this issue May 6, 2023 · 1 comment
Open

Possibility to seek within iterative decompression #275

codecat opened this issue May 6, 2023 · 1 comment

Comments

@codecat
Copy link

codecat commented May 6, 2023

I noticed that in #66, @unsightlygod implemented iterative decompression using the mz_zip_reader_extract_iter functions. Would it make sense or even be possible to add mz_zip_reader_extract_iter_seek to this, to seek within a file? Or would this not make sense in terms of compression?

Additionally, I noticed there is this unimplemented API, which looks to be pretty similar to the "iter" interface, which would be nice to have implemented.

#if 0
/* TODO */
	typedef void *mz_zip_streaming_extract_state_ptr;
	mz_zip_streaming_extract_state_ptr mz_zip_streaming_extract_begin(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags);
	mz_uint64 mz_zip_streaming_extract_get_size(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
	mz_uint64 mz_zip_streaming_extract_get_cur_ofs(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
	mz_bool mz_zip_streaming_extract_seek(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, mz_uint64 new_ofs);
	size_t mz_zip_streaming_extract_read(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, void *pBuf, size_t buf_size);
	mz_bool mz_zip_streaming_extract_end(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
#endif
@res2k
Copy link

res2k commented Sep 9, 2023

You can build seeking based on the existing mechanism...
To seek forward an amount of bytes, read that amount, but discard the data.
To seek backward, start iteration from the beginning, and seek forward.

Especially the latter is, of course, terribly inefficient.
However, if it's possible to "clone" the iterator (I didn't try), this could be used to somewhat lessen the overhead of seeking backwards: the idea would be to "clone" the iterator at some points (maybe an interesting point in the file if you know the structure, maybe something like "every N megabytes"), and then "seek forward" again from one of these clones (ie the closest one before the desired position).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants