zipflow icon indicating copy to clipboard operation
zipflow copied to clipboard

Change put() callback signature to inform about ptr validity

Open nigoroll opened this issue 2 years ago • 0 comments

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: ptr remains valid until after this call
  • 1: ptr or any ptr from a previous call will become invalid after this call
  • 2: this is the last ptr of 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.

nigoroll avatar Aug 20 '23 17:08 nigoroll