BaseNcoding.Base85.Encode C# (CSharp) Method

Encode() public method

public Encode ( byte data ) : string
data byte
return string
        public override string Encode(byte[] data)
        {
            unchecked
            {
                byte[] encodedBlock = new byte[5];
                int decodedBlockLength = 4;
                int resultLength = (int)(data.Length * (encodedBlock.Length / decodedBlockLength));
                if (PrefixPostfix)
                    resultLength += Prefix.Length + Postfix.Length;
                StringBuilder sb = new StringBuilder(resultLength);

                if (PrefixPostfix)
                    sb.Append(Prefix);

                int count = 0;
                uint tuple = 0;
                foreach (byte b in data)
                {
                    if (count >= decodedBlockLength - 1)
                    {
                        tuple |= b;
                        if (tuple == 0)
                            sb.Append('z');
                        else
                            EncodeBlock(encodedBlock.Length, sb, encodedBlock, tuple);
                        tuple = 0;
                        count = 0;
                    }
                    else
                    {
                        tuple |= (uint)(b << (24 - (count * 8)));
                        count++;
                    }
                }

                if (count > 0)
                    EncodeBlock(count + 1, sb, encodedBlock, tuple);

                if (PrefixPostfix)
                    sb.Append(Postfix);

                return sb.ToString();
            }
        }