<PackageReference Include="NUnit" Version="4.1.0" />

StreamsComparer

static class StreamsComparer
Comparator for two Streams.
using System; using System.IO; using System.Runtime.CompilerServices; namespace NUnit.Framework.Constraints.Comparers { internal static class StreamsComparer { private const int BUFFER_SIZE = 4096; [System.Runtime.CompilerServices.NullableContext(1)] public static EqualMethodResult Equal(object x, object y, ref Tolerance tolerance, ComparisonState state, NUnitEqualityComparer equalityComparer) { Stream stream = x as Stream; if (stream != null) { Stream stream2 = y as Stream; if (stream2 != null) { if (tolerance.HasVariance) return EqualMethodResult.ToleranceNotSupported; if (stream == stream2) return EqualMethodResult.ComparedEqual; if (!stream.CanRead) throw new ArgumentException("Stream is not readable", "expected"); if (!stream2.CanRead) throw new ArgumentException("Stream is not readable", "actual"); bool flag = stream.CanSeek && stream2.CanSeek; if (flag && stream.Length != stream2.Length) return EqualMethodResult.ComparedNotEqual; byte[] array = new byte[4096]; byte[] array2 = new byte[4096]; BinaryReader binaryReader = new BinaryReader(stream); BinaryReader binaryReader2 = new BinaryReader(stream2); long position = flag ? stream.Position : 0; long position2 = flag ? stream2.Position : 0; try { if (stream.CanSeek) binaryReader.BaseStream.Seek(0, SeekOrigin.Begin); if (stream2.CanSeek) binaryReader2.BaseStream.Seek(0, SeekOrigin.Begin); int num = 1; int num2 = 1; long num3 = 0; while (num > 0 && num2 > 0) { num = binaryReader.Read(array, 0, 4096); num2 = binaryReader2.Read(array2, 0, 4096); for (int i = 0; i < 4096; i++) { if (array[i] != array2[i]) { NUnitEqualityComparer.FailurePoint failurePoint = new NUnitEqualityComparer.FailurePoint(); failurePoint.Position = num3 + i; failurePoint.ExpectedHasData = true; failurePoint.ExpectedValue = array[i]; failurePoint.ActualHasData = true; failurePoint.ActualValue = array2[i]; equalityComparer.FailurePoints.Insert(0, failurePoint); return EqualMethodResult.ComparedNotEqual; } } num3 += 4096; } } finally { if (stream.CanSeek) stream.Position = position; if (stream2.CanSeek) stream2.Position = position2; } return EqualMethodResult.ComparedEqual; } } return EqualMethodResult.TypesNotSupported; } } }