예제 #1
0
        public void ApplyDelta(byte[] delta)
        {
            if (delta.Length == 0)
            {
                return;
            }

            var path     = GetFullPath();
            var tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetTempFileName());

            using (var fs = System.IO.File.OpenRead(path))
            {
                using (var fsout = new FileStream(tempPath, FileMode.Create))
                {
                    using (var deltaStream = new MemoryStream(delta))
                    {
                        var deltaReader  = new Octodiff.Core.BinaryDeltaReader(new MemoryStream(delta), LogProgressReporter.Get());
                        var deltaApplier = new Octodiff.Core.DeltaApplier {
                            SkipHashCheck = true
                        };
                        deltaApplier.Apply(fs, deltaReader, fsout);
                    }
                }
            }

            //move temp to original
            System.IO.File.Copy(tempPath, path, overwrite: true);
        }
예제 #2
0
        public byte[] CreateDelta(byte[] signature)
        {
            using (var fs = System.IO.File.OpenRead(GetFullPath()))
            {
                using (var deltaStream = new System.IO.MemoryStream())
                {
                    using (var signatureStream = new System.IO.MemoryStream(signature)) {
                        var signatureReader = new Octodiff.Core.SignatureReader(signatureStream, LogProgressReporter.Get());
                        var deltaWriter     = new Octodiff.Core.AggregateCopyOperationsDecorator(new Octodiff.Core.BinaryDeltaWriter(deltaStream));
                        var deltaBuilder    = new Octodiff.Core.DeltaBuilder();
                        deltaBuilder.BuildDelta(fs, signatureReader, deltaWriter);

                        return(deltaStream.ToArray());
                    }
                }
            }
        }