Samples

Below you find some samples of how to use the GDIFF library for different use cases.

Sample 1

How to generate a GDIFF between two strings (s1 and s2) and how to produce s2 using only s1 and the produced GDIFF.

string s1 = "String 1 that actually could be much much longer than this.";
string s2 = "String 2 that actually could be much much longer than this.";

byte[] gdiff = GDiff.Compute(s1, s2);
string s22 = GDiff.Apply(gdiff, s1);

// s22 should now equal s2.

Sample 2

How to generate a GDIFF between two versions of a document (v1.doc and v2.doc) and store it in a separate file. This sample also shows how to apply the GDIFF to v1.doc in order to produce a document that is equal to v2.doc.

using System.IO;

GDiff.Compute(
    new FileInfo(@"C:\temp\v1.doc"),
    new FileInfo(@"C:\temp\v2.doc"),
    new FileInfo(@"C:\temp\gdiff_v1-v2.gdiff")
);
GDiff.Apply(
    new FileInfo(@"C:\temp\gdiff_v1-v2.gdiff"),
    new FileInfo(@"C:\temp\v1.doc"),
    new FileInfo(@"C:\temp\v2-new.doc")
);

// The file 'C:\temp\v2-new.doc' should now be equal to the file 'C:\temp\v2.doc'.

Last edited Aug 9, 2008 at 10:49 AM by MikaBerglund, version 9

Comments

No comments yet.