Ejemplo n.º 1
0
        internal static int CopyStream(StreamAccessor 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 = WBXmlStreamHelper.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 = WBXmlStreamHelper.UpdateCrc32(crc, array, 0, num2);
                        }
                        count -= num2;
                        num   += num2;
                    }
                }while (num2 > 0 && count > 0);
            }
            finally
            {
                if (array != null)
                {
                    WBXmlStreamHelper.BytesBufferPool.Release(array);
                }
            }
            return(num);
        }
Ejemplo n.º 2
0
 internal static int CopyStream(StreamAccessor source, Stream target, int byteCount, out uint crc)
 {
     return(WBXmlStreamHelper.CopyStream(source, target, 0, byteCount, true, out crc));
 }
Ejemplo n.º 3
0
        internal static int CopyStream(StreamAccessor source, Stream target, int offset, int count)
        {
            uint num;

            return(WBXmlStreamHelper.CopyStream(source, target, offset, count, false, out num));
        }
Ejemplo n.º 4
0
 internal static int CopyStream(StreamAccessor source, Stream target)
 {
     return(WBXmlStreamHelper.CopyStream(source, target, int.MaxValue));
 }