Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does zlib allow decompressing from the middle of a file

Tags:

c

zlib

Does zlib allow decompressing from the middle of a file?
What I mean is, if I call inflate with a stream that points to the middle of compressed data without calling inflate to the data preceding the middle, would it work?

like image 435
小太郎 Avatar asked May 25 '11 07:05

小太郎


1 Answers

Copy from the zlib FAQ (the emphasis is mine):

28. Can I access data randomly in a compressed stream?

No, not without some preparation. If when compressing you periodically use Z_FULL_FLUSH, carefully write all the pending data at those points, and keep an index of those locations, then you can start decompression at those points. You have to be careful to not use Z_FULL_FLUSH too often, since it can significantly degrade compression. Alternatively, you can scan a deflate stream once to generate an index, and then use that index for random access. See examples/zran.c.

like image 159
pmg Avatar answered Oct 20 '22 23:10

pmg