public virtual void SetDictionary(byte[] b, int off, int len) { lock (this) { inflater.SetDictionary(b, off, len); } }
/// <summary> /// Decode a zRIF encoded string to a RIF byte array. /// </summary> /// <param name="zrif">The zRIF string</param> /// <returns>The RIF byte array, or null on error</returns> public static byte[] Decode(string zrif) { byte[] input, output = new byte[1024]; try { // Pad string if not a multiple of 4 if (zrif.Length % 4 != 0) { zrif += new string('=', 4 - (zrif.Length % 4)); } input = Convert.FromBase64String(zrif); } catch (Exception e) when(e is System.FormatException || e is System.NullReferenceException) { Console.Error.WriteLine($"[ERROR] {e.Message}"); return(null); } if (input.Length < 6) { Console.Error.WriteLine("[ERROR] zRIF length too short"); return(null); } if (((input[0] << 8) + input[1]) % 31 != 0) { Console.Error.WriteLine("[ERROR] zRIF header is corrupted"); return(null); } var inflater = new Inflater(); inflater.SetInput(input); inflater.Inflate(output); if (inflater.IsNeedingDictionary) { inflater.SetDictionary(zrif_dict); } switch (inflater.Inflate(output)) { case 1024: return(output); case 512: return(MemCpy(output, 0, 512)); default: return(null); } }