internal int DeflateNone(int flush)
{
// Stored blocks are limited to 0xffff bytes, pending_buf is limited
// to pending_buf_size, and each stored block has a 5 byte header:
int max_block_size = 0xffff;
int max_start;
if (max_block_size > pending.Length - 5) {
max_block_size = pending.Length - 5;
}
// Copy as much as possible from input to output:
while (true) {
// Fill the window as much as possible:
if (lookahead <= 1) {
_fillWindow ();
if (lookahead == 0 && flush == ZlibConstants.Z_NO_FLUSH)
return NeedMore;
if (lookahead == 0)
break; // flush the current block
}
strstart += lookahead;
lookahead = 0;
// Emit a stored block if pending_buf will be full:
max_start = block_start + max_block_size;
if (strstart == 0 || strstart >= max_start) {
// strstart == 0 is possible when wraparound on 16-bit machine
lookahead = (int)(strstart - max_start);
strstart = (int)max_start;
flush_block_only (false);
if (strm.AvailableBytesOut == 0)
return NeedMore;
}
// Flush if we may have to slide, otherwise block_start may become
// negative and the data will be gone:
if (strstart - block_start >= w_size - MIN_LOOKAHEAD) {
flush_block_only (false);
if (strm.AvailableBytesOut == 0)
return NeedMore;
}
}
flush_block_only (flush == ZlibConstants.Z_FINISH);
if (strm.AvailableBytesOut == 0)
return (flush == ZlibConstants.Z_FINISH) ? FinishStarted : NeedMore;
return flush == ZlibConstants.Z_FINISH ? FinishDone : BlockDone;
}