This is similar to a previous question, but the answers there don't satisfy my needs and my question is slightly different:
I currently use gzip compression for some very large files which contain sorted data. When the files are not compressed, binary search is a handy and efficient way to support seeking to a location in the sorted data.
But when the files are compressed, things get tricky. I recently found out about zlib's Z_FULL_FLUSH
option, which can be used during compression to insert "sync points" in the compressed output (inflateSync()
can then begin reading from various points in the file). This is OK, though files I already have would have to be recompressed to add this feature (and strangely gzip
doesn't have an option for this, but I'm willing to write my own compression program if I must).
It seems from one source that even Z_FULL_FLUSH
is not a perfect solution...not only is it not supported by all gzip archives, but the very idea of detecting sync points in archives may produce false positives (either by coincidence with the magic number for sync points, or due to the fact that Z_SYNC_FLUSH
also produces sync points but they are not usable for random access).
Is there a better solution? I'd like to avoid having auxiliary files for indexing if possible, and explicit, default support for quasi-random access would be helpful (even if it's large-grained--like being able to start reading at each 10 MB interval). Is there another compression format with better support for random reads than gzip?
Edit: As I mentioned, I wish to do binary search in the compressed data. I don't need to seek to a specific (uncompressed) position--only to seek with some coarse granularity within the compressed file. I just want support for something like "Decompress the data starting roughly 50% (25%, 12.5%, etc.) of the way into this compressed file."