public bool StreamsEqual(Stream stream1, Stream stream2, long size, bool async) { if (size == 0L) { if (stream1.CanSeek && stream2.CanSeek) { long num = stream1.Seek(0L, SeekOrigin.End); long num2 = stream1.Seek(0L, SeekOrigin.End); if (num != num2) { return false; } if ((num == 0L) && (num2 == 0L)) { return true; } size = num; stream1.Seek(0L, SeekOrigin.Begin); stream2.Seek(0L, SeekOrigin.Begin); } else { size = 0x7fffffffL; } } if (this.FBuffers1 == null) { this.FBuffers1 = new Buffers(0x40000); } if (this.FBuffers2 == null) { this.FBuffers2 = new Buffers(0x40000); } Buffers buffers = this.FBuffers1; Buffers buffers2 = this.FBuffers2; int length = this.FBuffers1.Buffer1.Length; AsyncBuffersEqualCaller caller = new AsyncBuffersEqualCaller(ByteArrayHelper.Equals); IAsyncResult result = null; while ((size > 0L) && (length == this.FBuffers1.Buffer1.Length)) { base.CheckSuspendingPending(); if (base.CancellationPending) { return false; } length = (int) Math.Min(size, (long) this.FBuffers1.Buffer1.Length); if (async) { length = ReadBuffersAsync(stream1, stream2, buffers, length); } else { int num4 = ReadBuffer(stream1, buffers.Buffer1, length); if (num4 != ReadBuffer(stream2, buffers.Buffer2, length)) { length = -1; } else { length = num4; } } if ((length < 0) || ((result != null) && !caller.EndInvoke(result))) { return false; } if (length == 0) { return true; } buffers2 = Interlocked.Exchange<Buffers>(ref buffers, buffers2); this.FProcessedSize += length; this.OnProgress(); result = caller.BeginInvoke(buffers2.Buffer1, buffers2.Buffer2, length, null, null); size -= length; } return caller.EndInvoke(result); }
private static int ReadBuffersAsync(Stream stream1, Stream stream2, Buffers buffers, int readSize) { int offset = 0; int num2 = 0; int num3 = 1; int num4 = 1; do { IAsyncResult asyncResult = null; IAsyncResult result2 = null; if (num3 > 0) { asyncResult = stream1.BeginRead(buffers.Buffer1, offset, readSize - offset, null, null); } if (num4 > 0) { result2 = stream2.BeginRead(buffers.Buffer2, num2, readSize - num2, null, null); } if (asyncResult != null) { num3 = stream1.EndRead(asyncResult); } if (result2 != null) { num4 = stream2.EndRead(result2); } offset += num3; num2 += num4; } while (((num3 != 0) || (num4 != 0)) && ((offset != readSize) || (num2 != readSize))); if (offset == num2) { return offset; } return -1; }