zlib: Don't trigger assertion error on flush

If you call z.flush();z.write('foo'); then it would try to write 'foo'
before the flush was done, triggering an assertion in the zlib binding.

Fix this by managing flush flags more appropriately.

Closes #4950