public static uint Sum(Stream inputStream) { #if PROFILING Profiler.BeginSample(); #endif if (inputStream == null) { throw new ArgumentNullException(nameof(inputStream)); } if (!inputStream.CanRead) { throw new InvalidOperationException("Input stream is not readable."); } uint value = HashInit(); int bytesRead; #if PROFILING long totalBytes = 0L; #endif while ((bytesRead = inputStream.Read(InternalBuffer, 0, InternalBuffer.Length)) > 0) { #if PROFILING totalBytes += bytesRead; #endif value = HashCore(value, InternalBuffer, 0, bytesRead); } var ret = HashFinal(value); #if PROFILING InternalLog.Debug($"[Crc32 Sum] Hashes a stream of {totalBytes} bytes takes {Profiler.EndSample().TotalMilliseconds} ms."); #endif return(ret); }