When a zlib stream has avail_in == 0, it will deflate with a Z_BUF_ERROR
to indicate that "no progress is possible". A zbuffer write with an
empty string will trigger this condition, and the write call
returns/raises an error/exception. The fix is simple: change the
do/while to a while loop, so that it only tries to deflate if there is
actually data to deflate.