public static long Decompress(byte[] inputBuffer, byte[] outputBuffer) { var result = 0; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { result = CompressionSettings.Get().UseOodle ? OodleLib.OodleLZ_Decompress(inputBuffer, outputBuffer) : KrakenLib.Decompress(inputBuffer, outputBuffer); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { result = KrakenLib.Decompress(inputBuffer, outputBuffer); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { result = OozNative.Kraken_Decompress(inputBuffer, outputBuffer); } else { throw new NotImplementedException(); } return(result); }
public void Kraken_Decompress(int level) { var testFile = Path.GetFullPath(Path.Combine("Resources", $"{level}_oodle.kark")); var outdir = Path.Combine(Environment.CurrentDirectory, "ooz"); Directory.CreateDirectory(outdir); using var fs = new FileStream(testFile, FileMode.Open, FileAccess.Read); using var br = new BinaryReader(fs); var oodleCompression = br.ReadBytes(4); if (!oodleCompression.SequenceEqual(new byte[] { 0x4b, 0x41, 0x52, 0x4b })) { throw new NotImplementedException(); } var size = br.ReadUInt32(); var buffer = br.ReadBytes((int)fs.Length - 8); // oodle var outBuffer1 = new byte[size]; { var unpackedSize = Oodle.Decompress(buffer, outBuffer1); var outpath = Path.Combine(outdir, "oodle.txt"); File.WriteAllBytes(outpath, outBuffer1); } #if _WINDOWS // kraken var outBuffer2 = new byte[size]; { KrakenLib.Load(); long unpackedSize2 = KrakenLib.Decompress(buffer, outBuffer2); var outpath2 = Path.Combine(outdir, "kraken.txt"); File.WriteAllBytes(outpath2, outBuffer2); } Assert.IsTrue(Enumerable.SequenceEqual(outBuffer1, outBuffer2)); #endif }