public int Inflate(byte[] bytes, int offset, int length)
{
// copy bytes from output to outputbytes if we have aviable bytes
// if buffer is not filled up. keep decoding until no input are available
// if decodeBlock returns false. Throw an exception.
int count = 0;
do
{
int copied = output.CopyTo(bytes, offset, length);
if (copied > 0)
{
if (using_gzip)
{
crc32 = DecodeHelper.UpdateCrc32(crc32, bytes, offset, copied);
uint n = streamSize + (uint)copied;
if (n < streamSize) // overflow, the gzip stream is probably malicious.
{
throw new InvalidDataException(SR.GetString(SR.StreamSizeOverflow));
}
streamSize = n;
}
offset += copied;
count += copied;
length -= copied;
}
if (length == 0) // filled in the bytes array
{
break;
}
// Decode will return false when more input is needed
} while (!Finished() && Decode());
if (state == InflaterState.VerifyingGZIPFooter) // finished reading CRC
// In this case finished is true and output window has all the data.
// But some data in output window might not be copied out.
{
if (output.AvailableBytes == 0)
{
if (crc32 != gZipDecoder.Crc32)
{
throw new InvalidDataException(SR.GetString(SR.InvalidCRC));
}
if (streamSize != gZipDecoder.StreamSize)
{
throw new InvalidDataException(SR.GetString(SR.InvalidStreamSize));
}
}
}
return(count);
}