Get the differences of two files
<p>In .NET, I need a way to compare two files. I thought of a class, which represents a diff:</p>

<pre><code>public enum DiffEntryState
{
    New,
    Removed,
    Changed
}    
public class DiffEntry
{
    public byte[] Bytes;
    public long FileOffset;
    public DiffEntryState State = BackupByteEntryState.Changed;
}
</code></pre>

<p>The names should be pretty self-explanatory. I thought of adding a State to each entry, so that I can distinguish between the cases were the first file is larger than the second or vice versa.</p>

<p>I'm wondering, if there is a common and fast way to retrieve the byte-by-byte differences of two files. I would simply create a stream for each file and compare chunks of these streams until one ends. Is there a better way, or does the Framework have a built-in solution? Keep in mind that I need the differences itself, not only the feedback that there ARE differences.</p>

<p>//Edit:</p>

<p><em>After sleeping a night over the problem, I guess I'm taking the wrong approach here. The whole tool is a backup solution, which will be able to save only the changed bytes and thus reduce the overall necessary space for the backup. Instead of saving a compressed 14 MB file each time, only 200k or less will be saved.</em></p>

<p><em>But, after thinking about the problem, I realized that it wouldn't be enough to save only the differences byte-by-byte. Take a Text for example:</em></p>

<p><em>"This is a string."
"This was a string."</em></p>

<p><em>As a matter of fact, the only change here is "is" to "was". But my approach would assume that the changed content is now "was a string". If this happens at the beginning of a huge file, well, this approach is useless.
Obviously, I need a way to index a file and detect all moved, copied or changed blocks in comparison to the original file.
Phew...</em></p>
