コード例 #1
0
        // Token: 0x0600159F RID: 5535 RVA: 0x0008016C File Offset: 0x0007E36C
        internal static int CopyStream(Stream source, Stream target, int offset, int count, bool needCrc, out uint crc)
        {
            byte[] array = null;
            int    num   = 0;

            crc = 0U;
            if (count == 0)
            {
                return(0);
            }
            if (count < 0)
            {
                count = int.MaxValue;
            }
            try
            {
                array = StreamHelper.bytesBufferPool.Acquire();
                if (array == null)
                {
                    throw new InvalidOperationException("buffer should never be null.");
                }
                int num2;
                if (source.CanSeek)
                {
                    source.Seek((long)offset, SeekOrigin.Begin);
                }
                else if (offset > 0)
                {
                    do
                    {
                        num2    = source.Read(array, 0, (offset < array.Length) ? offset : array.Length);
                        offset -= num2;
                    }while (num2 > 0 && offset > 0);
                }
                do
                {
                    num2 = source.Read(array, 0, (count < array.Length) ? count : array.Length);
                    if (num2 != 0)
                    {
                        target.Write(array, 0, num2);
                        if (needCrc)
                        {
                            crc = StreamHelper.UpdateCrc32(crc, array, 0, num2);
                        }
                        AirSyncDiagnostics.TraceBinaryData(ExTraceGlobals.RawBodyBytesTracer, null, array, num2);
                        count -= num2;
                        num   += num2;
                    }
                }while (num2 > 0 && count > 0);
            }
            finally
            {
                if (array != null)
                {
                    StreamHelper.bytesBufferPool.Release(array);
                }
            }
            return(num);
        }