Change put() callback signature to inform about ptr validity
As hinted by the last paragraph of the commit message given below, I would continue working on optimizations enabled by this change, if accepted.
Before this patch, the implied assumption was that the put() ptr argument was only valid for that particular call, so a put() implementation had to either write the data immediately or buffer it.
The end of the zip file was signaled through a NULL ptr argument, so the put() implementation had no way of efficiently handling the last bit of data.
This patch introduces a breaking signature change of the put() function: A flag argument is added, which takes one of three values depending on the validity of the ptr argument:
-
0:ptrremains valid until after this call -
1:ptror anyptrfrom a previous call will become invalid after this call -
2: this is the lastptrof the file
This allows put() implementations to avoid buffering and optimize handling of the last bytes of the zip file.
Note that with this patch, the implementation still misses optimizations enabled through this change, for example, after a deflate(Z_FINISH), zip->comp remains valid until the next call, so we might be able to use flag = 0 here.