zlib: introduce pending close state

zlib should not crash in `close()` if the write is still in progress.

fix #7101
Merge remote-tracking branch 'upstream/v0.10' into v0.10