Пример #1
0
        public override int Read(byte[] array, int offset, int count)
        {
            EnsureDecompressionMode();
            ValidateParameters(array, offset, count);
            EnsureNotDisposed();

            int bytesRead;
            int currentOffset  = offset;
            int remainingCount = count;

            while (true)
            {
                bytesRead       = inflater.Inflate(array, currentOffset, remainingCount);
                currentOffset  += bytesRead;
                remainingCount -= bytesRead;

                if (remainingCount == 0)
                {
                    break;
                }

                if (inflater.Finished())
                {
                    break;
                }

                Debug.Assert(inflater.NeedsInput(), "We can only run into this case if we are short of input");

                int bytes = _stream.Read(buffer, 0, buffer.Length);
                if (bytes == 0)
                {
                    break;      //Do we want to throw an exception here?
                }

                inflater.SetInput(buffer, 0, bytes);
            }

            return(count - remainingCount);
        }