Inflate() private méthode

private Inflate ( ZLibNative flushCode ) : ZLibNative.ErrorCode
flushCode ZLibNative
Résultat ZLibNative.ErrorCode
Exemple #1
0
        public override int ReadByte()
        {
            EnsureDecompressionMode();
            EnsureNotDisposed();

            // Try to read a single byte from zlib without allocating an array, pinning an array, etc.
            // If zlib doesn't have any data, fall back to the base stream implementation, which will do that.
            byte b;

            return(_inflater.Inflate(out b) ? b : base.ReadByte());
        }
Exemple #2
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())
                {
                    // if we finished decompressing, we can't have anything left in the outputwindow.
                    Debug.Assert(_inflater.AvailableOutput == 0, "We should have copied all stuff out!");
                    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;
                }
                else if (bytes > _buffer.Length)
                {
                    // The stream is either malicious or poorly implemented and returned a number of
                    // bytes larger than the buffer supplied to it.
                    throw new InvalidDataException(SR.GenericInvalidData);
                }

                _inflater.SetInput(_buffer, 0, bytes);
            }

            return(count - remainingCount);
        }
Exemple #3
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())
                {
                    // if we finished decompressing, we can't have anything left in the outputwindow.
                    Debug.Assert(_inflater.AvailableOutput == 0, "We should have copied all stuff out!");
                    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);
        }
Exemple #4
0
        // Read data from this stream.
        public override int Read(byte[] buffer, int offset, int count)
        {
            int temp;

            if (stream == null)
            {
                throw new ObjectDisposedException
                          ("Exception_Disposed");
            }
            if (mode != CompressionMode.Decompress)
            {
                throw new NotSupportedException("IO_NotSupp_Read");
            }
            ValidateBuffer(buffer, offset, count);
            for (;;)
            {
                temp = inflater.Inflate(buffer, offset, count);
                if (temp > 0)
                {
                    return(temp);
                }
                if (inflater.IsNeedingDictionary)
                {
                    throw new IOException
                              ("IO_Decompress_NeedDict");
                }
                else if (inflater.IsFinished)
                {
                    return(0);
                }
                else if (inflater.IsNeedingInput)
                {
                    temp = stream.Read(buf, 0, buf.Length);
                    if (temp <= 0)
                    {
                        throw new IOException
                                  ("IO_Decompress_Truncated");
                    }
                    inflater.SetInput(buf, 0, temp);
                }
                else
                {
                    throw new IOException
                              ("IO_Decompress_Invalid");
                }
            }
        }