public int Inflate(byte[] bytes, int offset, int length)
        {
            // copy bytes from output to outputbytes if we have available 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 = 0;
                if (_uncompressedSize == -1)
                {
                    copied = _output.CopyTo(bytes, offset, length);
                }
                else
                {
                    if (_uncompressedSize > _currentInflatedCount)
                    {
                        length = (int)Math.Min(length, _uncompressedSize - _currentInflatedCount);
                        copied = _output.CopyTo(bytes, offset, length);
                        _currentInflatedCount += copied;
                    }
                    else
                    {
                        _state = InflaterState.Done;
                        _output.ClearBytesUsed();
                    }
                }
                if (copied > 0)
                {
                    if (_hasFormatReader)
                    {
                        _formatReader.UpdateWithBytesRead(bytes, offset, copied);
                    }

                    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.VerifyingFooter)
            {  // 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)
                {
                    _formatReader.Validate();
                }
            }

            return(count);
        }
        public int Inflate(byte[] bytes, int offset, int length)
        {
            // copy bytes from output to outputbytes if we have available bytes
            // if buffer is not filled up. keep decoding until no input are available
            // if decodeBlock returns false. Throw an exception.
            int count = 0;

            UnityEngine.Debug.Log("Inflater.Inflate(...) offset " + offset + " length " + length);

            int iter = 0;

            do
            {
                int copied = output.CopyTo(bytes, offset, length);
                UnityEngine.Debug.Log("Inflater.Inflate(...) iteration " + (++iter) + ", copied " + copied + " out of an attempted " + length);

                if (copied > 0)
                {
                    if (hasFormatReader)
                    {
                        formatReader.UpdateWithBytesRead(bytes, offset, copied);
                    }

                    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.VerifyingFooter)    // 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)
                {
                    formatReader.Validate();
                }
            }

            return(count);
        }
Exemple #3
0
        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.
            var count = 0;

            do
            {
                var copied = _output.CopyTo(bytes, offset, length);
                if (copied > 0)
                {
                    if (_hasFormatReader)
                    {
                        _formatReader.UpdateWithBytesRead(bytes, offset, copied);
                    }

                    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 (!this.Finished() && this.Decode());

            if (_state != InflaterState.VerifyingFooter)
            {
                return(count); // 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)
            {
                _formatReader.Validate();
            }

            return(count);
        }
Exemple #4
0
        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.
            var count = 0;

            do
            {
                var copied = output.CopyTo(bytes, offset, length);
                if (copied > 0)
                {
                    if (hasFormatReader)
                    {
                        formatReader.UpdateWithBytesRead(bytes, offset, copied);
                    }

                    offset += copied;
                    count  += copied;
                    length -= copied;
                }

                if (length == 0)
                {
                    break;
                }
                // Decode will return false when more input is needed
            } while (!Finished() && Decode());

            if (state == InflaterState.VerifyingFooter)
            {
                if (output.AvailableBytes == 0)
                {
                    formatReader.Validate();
                }
            }

            return(count);
        }