public static byte[] CompressAndEncode(object input) { //https://github.com/fuzeman/rencode-sharp/issues/6 var inputString = Rencode.Encode(input); byte[] inputBytes = inputString.Select(Convert.ToByte).ToArray(); using ( ZlibStream zStream = new ZlibStream(new MemoryStream(inputBytes), Ionic.Zlib.CompressionMode.Compress, CompressionLevel.Default)) { var compressedBytes = zStream.ReadFully(); return compressedBytes; } }