Example #1
0
        internal static void SaveDiffToFile(Stream origStream, Stream modifiedStream, Stream diffStream)
        {
            VCCoder      coder  = new VCCoder(origStream, modifiedStream, diffStream);
            VCDiffResult result = coder.Encode(); //encodes with no checksum and not interleaved

            if (result != VCDiffResult.SUCCESS)
            {
                //error was not able to encode properly
            }
        }
Example #2
0
        private void DoEncode(string outPatchFile, string oldFile, string newFile)
        {
            byte[] hash    = GetSha1FromFile(oldFile);
            byte[] newHash = GetSha1FromFile(newFile);
            using (FileStream output = new FileStream(outPatchFile, FileMode.Create, FileAccess.Write))
                using (FileStream dict = new FileStream(oldFile, FileMode.Open, FileAccess.Read))
                    using (FileStream target = new FileStream(newFile, FileMode.Open, FileAccess.Read))
                    {
                        output.Write(hash, 0, 20);
                        output.Write(newHash, 0, 20);

                        VCCoder      coder  = new VCCoder(dict, target, output);
                        VCDiffResult result = coder.Encode(); //encodes with no checksum and not interleaved
                        if (result != VCDiffResult.SUCCESS)
                        {
                            throw new Exception("DoEncode was not able to encode properly file: " + Path.GetFileName(oldFile));
                        }
                    }
        }
Example #3
0
        /// <summary>
        /// Create delta file from 2 files
        /// </summary>
        /// <param name="modified">File that the delta will update to</param>
        /// <param name="original">File that the delta file will use as the base</param>
        /// <param name="output">Output path for the delta file</param>
        private static void DoEncode(string modified, string original, string output)
        {
            using (FileStream outputS = new FileStream(output, FileMode.CreateNew, FileAccess.Write))
                using (FileStream dictS = new FileStream(original, FileMode.Open, FileAccess.Read))
                    using (FileStream targetS = new FileStream(modified, FileMode.Open, FileAccess.Read))
                    {
                        VCCoder      coder  = new VCCoder(dictS, targetS, outputS);
                        VCDiffResult result = coder.Encode(true, true);         //encodes with no checksum and not interleaved
                        if (result != VCDiffResult.SUCCESS)
                        {
                            Debug.WriteLine($"Something got f****d up, how to check please help");
                            //error was not able to encode properly
                        }

                        if (outputS.Length <= 5)
                        {
                            outputS.Close();
                            File.Delete(output);
                        }
                    }
        }
        public void TestEncodeAndDecodeShouldBeTheSame()
        {
            int size = 20 * 1024 * 1024; // 20 MB

            byte[] oldData = CreateRandomByteArray(size);
            byte[] newData = new byte[size];

            oldData.CopyTo(newData, 0);

            AddRandomPiecesIn(oldData);

            var sOld   = new MemoryStream(oldData);
            var sNew   = new MemoryStream(newData);
            var sDelta = new MemoryStream(new byte[size], true);

            var coder = new VCCoder(sOld, sNew, sDelta);

            Assert.AreEqual(VCDiffResult.Succes, coder.Encode());

            TestContext.Out.WriteLine($"Delta is {sDelta.Position / 1024 / 1024} MB's");

            sDelta.SetLength(sDelta.Position);
            sDelta.Position = 0;
            sOld.Position   = 0;
            sNew.Position   = 0;

            var sPatched = new MemoryStream(new byte[size], true);

            var decoder = new VCDecoder(sOld, sDelta, sPatched);

            Assert.AreEqual(VCDiffResult.Succes, decoder.Start());
            Assert.AreEqual(VCDiffResult.Succes, decoder.Decode(out long bytesWritten));

            TestContext.Out.WriteLine($"Written {bytesWritten / 1024 / 1024} MB's");

            Assert.AreEqual(sNew.ToArray(), sPatched.ToArray());
        }
Example #5
0
        private static VCDiffResult Encode(Stream sold, Stream snew, Stream sout, int bufferSize)
        {
            VCCoder encoder = new VCCoder(sold, snew, sout, bufferSize);

            return(encoder.Encode());
        }