示例#1
0
        public async Task Setup()
        {
            _rdiff = new Rdiff();
            _v1    = new byte[Length];
            new Random(5).NextBytes(_v1);
            _v2 = new byte[Length];
            for (int i = 0; i < Length; i++)
            {
                _v2[i] = (byte)(_v1[i] + 1);
            }

            var sig = new MemoryStream();
            await _rdiff.SignatureAsync(new MemoryStream(_v1), sig);

            _signature = sig.ToArray();
        }
示例#2
0
        public async Task Setup()
        {
            _rdiff = new Rdiff();
            _v1    = new byte[Length];
            new Random(5).NextBytes(_v1);

            var sigStream = new MemoryStream();
            await _rdiff.SignatureAsync(
                new MemoryStream(_v1),
                sigStream);

            var sig = sigStream.ToArray();

            var deltaNoChange = new MemoryStream();
            await _rdiff.DeltaAsync(
                new MemoryStream(sig),
                new MemoryStream(_v1),
                deltaNoChange);

            _deltaNoChange = deltaNoChange.ToArray();

            var v2 = new byte[Length];

            for (int i = 0; i < Length; i++)
            {
                v2[i] = (byte)(_v1[i] + 1);
            }

            var deltaAllChange = new MemoryStream();
            await _rdiff.DeltaAsync(
                new MemoryStream(sig),
                new MemoryStream(v2),
                deltaAllChange);

            _deltaAllChange = deltaAllChange.ToArray();
        }
示例#3
0
 public async Task Signature()
 {
     await _rdiff.SignatureAsync(
         new MemoryStream(_content),
         new NullStream());
 }
示例#4
0
        public static async Task Test(
            TestDirectory files,
            BlockSequence blockSequence,
            Mutation mutation,
            SignatureOptions options,
            int?blockToMutate = null)
        {
            var rdiff   = new Rdiff(files);
            var timings = new List <(TestFile, TimeSpan)>();
            var timer   = Stopwatch.StartNew();

            blockSequence.WriteTo(files.Path(TestFile.v1));

            timings.Add((TestFile.v1, timer.Elapsed));
            timer.Restart();

            using (var v1 = files.Read(TestFile.v1))
                using (var sig = files.Write(TestFile.sig))
                {
                    await _rdiff.SignatureAsync(v1, sig, options);
                }

            timings.Add((TestFile.sig, timer.Elapsed));
            timer.Restart();

            rdiff.Signature(TestFile.v1, TestFile.rs_sig, options);

            timings.Add((TestFile.rs_sig, timer.Elapsed));
            await AssertEqual(files, TestFile.rs_sig, TestFile.sig);

            timer.Restart();

            using (var v2 = files.Write(TestFile.v2))
                using (var v1 = files.Read(TestFile.v1))
                {
                    await mutation.WriteTo(
                        blockSequence.Blocks(v1),
                        i => i == (blockToMutate ?? i),
                        v2);
                }

            timings.Add((TestFile.v2, timer.Elapsed));
            timer.Restart();

            using (var sig = files.Read(TestFile.sig))
                using (var v2 = files.Read(TestFile.v2))
                    using (var delta = files.Write(TestFile.delta))
                    {
                        await _rdiff.DeltaAsync(sig, v2, delta);
                    }

            timings.Add((TestFile.delta, timer.Elapsed));
            timer.Restart();

            rdiff.Delta(TestFile.sig, TestFile.v2, TestFile.rs_delta);

            timings.Add((TestFile.rs_delta, timer.Elapsed));
            await AssertEqual(files, TestFile.rs_delta, TestFile.delta);

            timer.Restart();

            using (var delta = files.Read(TestFile.delta))
                using (var v1 = files.Read(TestFile.v1))
                    using (var patched = files.Write(TestFile.patched))
                    {
                        await _rdiff.PatchAsync(v1, delta, patched);
                    }

            timings.Add((TestFile.patched, timer.Elapsed));
            await AssertEqual(files, TestFile.v2, TestFile.patched);

            foreach (var(file, duration) in timings)
            {
                // Console.WriteLine($"{file}: {duration}");
            }
        }