public void setStrat(EDeflateCompressStrategy strat) { if (strat == EDeflateCompressStrategy.Filtered) { deflater.SetStrategy(DeflateStrategy.Filtered); } else if (strat == EDeflateCompressStrategy.Huffman) { deflater.SetStrategy(DeflateStrategy.HuffmanOnly); } else { deflater.SetStrategy(DeflateStrategy.Default); } }
/// <summary> /// Encode a RIF byte array to zRIF string. /// </summary> /// <param name="zrif">The zRIF string.</param> /// <returns>The zRIF string or null on error.</returns> public static string Encode(byte[] rif) { byte[] output = new byte[128 + 2]; if ((rif.Length != 512) && (rif.Length != 1024)) { Console.Error.WriteLine("[ERROR] invalid RIF length"); return(null); } var deflater = new Deflater(); deflater.SetDictionary(zrif_dict); deflater.SetInput(rif); deflater.SetLevel(Deflater.BEST_COMPRESSION); deflater.SetStrategy(DeflateStrategy.Default); deflater.Finish(); int size = deflater.Deflate(output, 0, output.Length - 2); if (!deflater.IsFinished) { Console.Error.WriteLine("[ERROR] Deflate error"); return(null); } // Don't have that much control over Window size so our header needs to be adjusted. if ((output[0] == 0x78) && (output[1] == 0xF9)) { output[0] = 0x28; output[1] = 0xEE; } // Adjust the size to be a multiple of 3 so that we don't get padding return(Convert.ToBase64String(output, 0, ((size + 2) / 3) * 3)); }
public void setStrat(EDeflateCompressStrategy strat) { DeflateStrategy newDeflateStrategy = DeflateStrategy.Default; if (strat == EDeflateCompressStrategy.Filtered) { newDeflateStrategy = DeflateStrategy.Filtered; } else if (strat == EDeflateCompressStrategy.Huffman) { newDeflateStrategy = DeflateStrategy.HuffmanOnly; } else { newDeflateStrategy = DeflateStrategy.Default; } deflater.SetStrategy(newDeflateStrategy); }