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);
}
}