private void ReadOctoDeltaHeader()
        {
            var version = reader.ReadByte();

            if (version != OctoBinaryFormat.Version)
            {
                throw new InvalidDataException("The delta file uses a newer file format than this program can handle.");
            }

            var hashAlgorithmName = reader.ReadString();

            hashAlgorithm = SupportedAlgorithms.Hashing.Create(hashAlgorithmName);

            var hashLength = reader.ReadInt32();

            expectedHash = reader.ReadBytes(hashLength);
            var endOfMeta = reader.ReadBytes(OctoBinaryFormat.EndOfMetadata.Length);

            if (!StructuralComparisons.StructuralEqualityComparer.Equals(OctoBinaryFormat.EndOfMetadata, endOfMeta))
            {
                throw new InvalidDataException("The delta file appears to be corrupt.");
            }

            _metadata = new DeltaMetadata
            {
                HashAlgorithm             = hashAlgorithmName,
                ExpectedFileHashAlgorithm = hashAlgorithmName,
                ExpectedFileHash          = Convert.ToBase64String(expectedHash)
            };

            type = RsyncFormatType.Octodiff;
        }
Example #2
0
        public void WriteMetadata(DeltaMetadata metadata)
        {
            writer.Write(FastRsyncBinaryFormat.DeltaHeader);
            writer.Write(FastRsyncBinaryFormat.Version);
            var metadataStr = JsonConvert.SerializeObject(metadata, JsonSerializationSettings.JsonSettings);

            writer.Write(metadataStr);
        }
        private void ReadFastRsyncDeltaHeader()
        {
            var version = reader.ReadByte();

            if (version != FastRsyncBinaryFormat.Version)
            {
                throw new InvalidDataException("The delta file uses a newer file format than this program can handle.");
            }

            var metadataStr = reader.ReadString();

            _metadata = JsonConvert.DeserializeObject <DeltaMetadata>(metadataStr, JsonSerializationSettings.JsonSettings);

            hashAlgorithm = SupportedAlgorithms.Hashing.Create(_metadata.HashAlgorithm);
            expectedHash  = Convert.FromBase64String(_metadata.ExpectedFileHash);

            type = RsyncFormatType.FastRsync;
        }