Пример #1
0
        public static void WriteBlock(BinaryWriter s, byte[] block, SignatureJobSettings settings)
        {
            int num = CalculateWeakSum(block);

            if (settings.MagicNumber != MagicNumber.Blake2Signature)
            {
                throw new NotImplementedException("Non-blake2 hashes aren't supported");
            }
            byte[] buffer = CalculateBlake2StrongSum(block);
            StreamHelpers.WriteBigEndian(s, (ulong)num);
            s.Write(buffer, 0, settings.StrongSumLength);
        }
Пример #2
0
        public DeltaStream(Stream signatureStream, Stream inputStream)
        {
            SignatureFile signatures = SignatureHelpers.ParseSignatureFile(signatureStream);
            IEnumerable <OutputCommand> enumerable = DeltaCalculator.ComputeCommands(new BinaryReader(inputStream), signatures);

            commandsToOutput     = enumerable.GetEnumerator();
            currentCommandStream = new MemoryStream();
            BinaryWriter binaryWriter = new BinaryWriter(currentCommandStream);

            StreamHelpers.WriteBigEndian(binaryWriter, 1920139830uL);
            binaryWriter.Flush();
            currentCommandStream.Seek(0L, SeekOrigin.Begin);
        }
Пример #3
0
        public DeltaStream(Stream signatureStream, Stream inputStream)
        {
            var signature   = SignatureHelpers.ParseSignatureFile(signatureStream);
            var inputReader = new BinaryReader(inputStream);
            var commands    = DeltaCalculator.ComputeCommands(inputReader, signature);

            this.commandsToOutput = commands.GetEnumerator();

            this.currentCommandStream = new MemoryStream();
            var writer = new BinaryWriter(this.currentCommandStream);

            StreamHelpers.WriteBigEndian(writer, (uint)MagicNumber.Delta);
            writer.Flush();
            this.currentCommandStream.Seek(0, SeekOrigin.Begin);
        }
Пример #4
0
        public static void WriteCommand(BinaryWriter s, OutputCommand command)
        {
            if (command.Kind == CommandKind.Literal)
            {
                if (command.Literal.Count <= 64)
                {
                    if (command.Literal.Count == 0)
                    {
                        throw new ArgumentException("Literal must have at least 1 byte");
                    }

                    // literals from 1..64 have a command code equal to the length
                    s.Write((byte)command.Literal.Count);
                }
                else
                {
                    // longer literals encode the length
                    int  lengthBytes = GetSizeNeeded((ulong)command.Literal.Count);
                    int  idx         = SizeToIdx(lengthBytes);
                    byte commandCode = (byte)(MinVariableLiteral + idx);
                    s.Write(commandCode);
                    StreamHelpers.WriteBigEndian(s, (ulong)command.Literal.Count, lengthBytes);
                }

                s.Write(command.Literal.ToArray());
            }
            else if (command.Kind == CommandKind.Copy)
            {
                int  positionBytes = GetSizeNeeded(command.Position);
                int  lengthBytes   = GetSizeNeeded(command.Length);
                byte positionIdx   = SizeToIdx(positionBytes);
                byte lengthIdx     = SizeToIdx(lengthBytes);

                byte commandCode = (byte)(MinCopyCommand + positionIdx * 4 + lengthIdx);
                s.Write(commandCode);
                StreamHelpers.WriteBigEndian(s, command.Position, positionBytes);
                StreamHelpers.WriteBigEndian(s, command.Length, lengthBytes);
            }
            else if (command.Kind == CommandKind.End)
            {
                s.Write(0); // command code for end
            }
        }
Пример #5
0
 public static void WriteCommand(BinaryWriter s, OutputCommand command)
 {
     if (command.Kind == CommandKind.Literal)
     {
         if (command.Literal.Count <= 64)
         {
             if (command.Literal.Count == 0)
             {
                 throw new ArgumentException("Literal must have at least 1 byte");
             }
             s.Write((byte)command.Literal.Count);
         }
         else
         {
             int  sizeNeeded = GetSizeNeeded((ulong)command.Literal.Count);
             int  num        = SizeToIdx(sizeNeeded);
             byte value      = (byte)(65 + num);
             s.Write(value);
             StreamHelpers.WriteBigEndian(s, (ulong)command.Literal.Count, sizeNeeded);
         }
         s.Write(command.Literal.ToArray());
     }
     else if (command.Kind == CommandKind.Copy)
     {
         int  sizeNeeded2 = GetSizeNeeded(command.Position);
         int  sizeNeeded3 = GetSizeNeeded(command.Length);
         byte b           = SizeToIdx(sizeNeeded2);
         byte b2          = SizeToIdx(sizeNeeded3);
         byte value2      = (byte)(69 + b * 4 + b2);
         s.Write(value2);
         StreamHelpers.WriteBigEndian(s, command.Position, sizeNeeded2);
         StreamHelpers.WriteBigEndian(s, command.Length, sizeNeeded3);
     }
     else if (command.Kind == CommandKind.End)
     {
         s.Write(0);
     }
 }
Пример #6
0
 public static void WriteHeader(BinaryWriter s, SignatureJobSettings settings)
 {
     StreamHelpers.WriteBigEndian(s, (uint)settings.MagicNumber);
     StreamHelpers.WriteBigEndian(s, (uint)settings.BlockLength);
     StreamHelpers.WriteBigEndian(s, (uint)settings.StrongSumLength);
 }