private void WriteInternal(byte[] buffer, int offset, int count, int flush)
{
_zstream.next_in = buffer;
_zstream.next_in_index = offset;
_zstream.avail_in = count;
while (true)
{
_zstream.next_out = _block;
_zstream.next_out_index = 0;
_zstream.avail_out = _block.Length;
int err;
if (_compress)
{
err = _zstream.deflate(flush);
}
else
{
err = _zstream.inflate(flush);
}
if (err != JZlib.Z_OK && (flush == JZlib.Z_FINISH && err != JZlib.Z_STREAM_END))
{
throw new InvalidOperationException(string.Format("Error while {0}flating - {1}.", (_compress ? "de" : "in"), _zstream.msg));
}
_output.Write(_block, 0, _block.Length - _zstream.avail_out);
if (_zstream.avail_out == 0)
{
continue;
}
if (_zstream.avail_in == 0)
{
break;
}
}
}