2

I'm trying to keep files in sync over network. Instead of transferring the whole file on each change, I'd like to find and compress the changed parts and transfer only those, very similar to e.g. subversion. Is there a reliable C# solution to this problem, or do I have to write it myself?

mafu
  • 31,798
  • 42
  • 154
  • 247

3 Answers3

2

The key word is "diff algorithm". There are several implementations in c#.

Diff.NET and A Generic, Reusable Diff Algorithm in C# looks like reasonable choices. Google will find you another couple of hundred choices.

Be aware that most diff algorithms are specially crafted to handle line based text files.
If you want to diff binary data or parts of lines you need to be more careful when picking a diff library.

If you want to compress the diff too you can use the System.IO.Compression.GZipStream class.

Albin Sunnanbo
  • 46,430
  • 8
  • 69
  • 108
1

This post may help you.

In general you are looking for a way to binary-compare the new file to the old file and then strip out just the changed bytes, compress them, transfer them to the other system, decompress them and insert them into the file at the appropriate locations. So it sounds like you'll need an application running on each end (perhaps the same application if you want it to work both ways).

Community
  • 1
  • 1
Josh M.
  • 26,437
  • 24
  • 119
  • 200
0

in which format do you have the changes? byte[], string or stream?

have a look here: Compress and decompress strings in C#

Davide Piras
  • 43,984
  • 10
  • 98
  • 147
  • I do not yet have the changes, that's part of the question. :) The files themselves are byte[] – mafu Mar 10 '11 at 13:00