ADBaseLibrary.Matroska.MatroskaExtensions.CopyBytes C# (CSharp) Method

CopyBytes() public static method

public static CopyBytes ( this reader, System.UInt64 length, BinaryWriter writer, HashAlgorithm algo = null ) : void
reader this
length System.UInt64
writer System.IO.BinaryWriter
algo System.Security.Cryptography.HashAlgorithm
return void
        public static void CopyBytes(this BinaryReader reader, UInt64 length, BinaryWriter writer, HashAlgorithm algo=null)
        {
            byte[] buffer = new byte[32768];
            int read;
            int max = (int)(length < 32768 ? length : 32768);
            while ((read = reader.BaseStream.Read(buffer, 0, max)) > 0)
            {
                writer.BaseStream.Write(buffer, 0, read);
                algo?.TransformBlock(buffer, 0, read, buffer, 0);
                length -= (ulong)read;
                max = (int)(length < 32768 ? length : 32768);
            }
        }