public bool Equals(FileInfoStream fs1, FileInfoStream fs2)
        {
            if (fs1 == null)
            {
                throw new ArgumentNullException(nameof(fs1));
            }
            if (fs2 == null)
            {
                throw new ArgumentNullException(nameof(fs2));
            }

            if (fs1.File.Length != fs2.File.Length)
            {
                return(false);
            }
            if (fs1.File.Length == 0)
            {
                return(true);
            }

            fs1.Seek(0, SeekOrigin.Begin);
            fs2.Seek(0, SeekOrigin.Begin);

            return(InternalEquals(fs1, fs2));
        }
 private static void ReadFile(FileInfoStream fs, byte[] buffer, int offset, int count)
 {
     try
     {
         fs.SafeRead(buffer, offset, count);
     }
     catch (IOException ex)
     {
         throw new FileSystemInfoException(fs.File, ex);
     }
 }
        private bool InternalEquals(FileInfoStream fs1, FileInfoStream fs2)
        {
            var bytesLeft = fs1.Length;

            do
            {
                var len = (int)Math.Min(bytesLeft, BufferSize);

                ReadFile(fs1, _buffer1, 0, len);
                ReadFile(fs2, _buffer2, 0, len);

                if (NativeMethods.memcmp(_buffer1, _buffer2, new UIntPtr((uint)len)) != 0)
                {
                    return(false);
                }

                bytesLeft -= len;
            } while (bytesLeft > 0);

            return(true);
        }
Exemple #4
0
        private bool InternalEquals(FileInfoStream fs1, FileInfoStream fs2)
        {
            var bytesLeft = fs1.Length;
            var read      = (int)Math.Min(bytesLeft, BufferSize);

            if (fs1.File != _lastFile1)
            {
                ReadFile(fs1, _buffer1, 0, read);
                _lastFile1 = fs1.File;
            }

            ReadFile(fs2, _buffer2, 0, read);

            if (NativeMethods.memcmp(_buffer1, _buffer2, new UIntPtr((uint)read)) != 0)
            {
                return(false);
            }

            if (read < bytesLeft)
            {
                _lastFile1 = null;

                while ((bytesLeft -= read) > 0)
                {
                    read = (int)Math.Min(bytesLeft, BufferSize);

                    ReadFile(fs1, _buffer1, 0, read);
                    ReadFile(fs2, _buffer2, 0, read);

                    if (NativeMethods.memcmp(_buffer1, _buffer2, new UIntPtr((uint)read)) != 0)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }