// Used for protobuf json strings. public static byte[] Deflate <T>(string name, T data) { var jsonData = Encoding.UTF8.GetBytes(name + ":" + CreateString(data) + "\0"); var jsonDataLength = BitConverter.GetBytes(jsonData.Length); var zlibHeader = new byte[] { 0x78, 0x9C }; var compressedData = Zlib.Deflate(jsonData); var uncompressedAdler = BitConverter.GetBytes(Adler32.Calculate(jsonData)).Reverse().ToArray(); return(jsonDataLength.Concat(zlibHeader).Concat(compressedData).Concat(uncompressedAdler).ToArray()); }
public void DeflateRencode() { var list = "hello_world"; string encode = Rencode.Encode(list); byte[] encodedBytes = encode.Select(Convert.ToByte).ToArray(); byte[] bytes = Zlib.Deflate(encodedBytes); string base64 = Base64.Encode(bytes); }
public byte[] Encode(byte[] bytes) { return(Zlib.Deflate(bytes)); }