CopyTo() публичный Метод

public CopyTo ( byte output, int offset, int length ) : int
output byte
offset int
length int
Результат int
Пример #1
0
        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);
        }
Пример #2
0
        public int Inflate(Span <byte> bytes)
        {
            // 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);
                }
                else
                {
                    if (_uncompressedSize > _currentInflatedCount)
                    {
                        bytes  = bytes.Slice(0, (int)Math.Min(bytes.Length, _uncompressedSize - _currentInflatedCount));
                        copied = _output.CopyTo(bytes);
                        _currentInflatedCount += copied;
                    }
                    else
                    {
                        _state = InflaterState.Done;
                        _output.ClearBytesUsed();
                    }
                }
                if (copied > 0)
                {
                    bytes  = bytes.Slice(copied, bytes.Length - copied);
                    count += copied;
                }

                if (bytes.IsEmpty)
                {
                    // filled in the bytes buffer
                    break;
                }
                // Decode will return false when more input is needed
            } while (!Finished() && Decode());

            return(count);
        }
Пример #3
0
        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)
                {
                    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());

            return(count);
        }
Пример #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.
            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);
        }
Пример #5
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.
            int count = 0;

            do
            {
                int 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 (!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);
        }