From bc06cb5bdba4572be8c68de34dffbca49bcc38d7 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 24 Apr 2024 00:49:34 -0400 Subject: [PATCH] Port extension code for zlib constant names from UnshieldSharp --- SabreTools.Compression/zlib/zlibConst.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/SabreTools.Compression/zlib/zlibConst.cs b/SabreTools.Compression/zlib/zlibConst.cs index 244b47a..f15f6af 100644 --- a/SabreTools.Compression/zlib/zlibConst.cs +++ b/SabreTools.Compression/zlib/zlibConst.cs @@ -19,5 +19,29 @@ namespace SabreTools.Compression.zlib public const int Z_MEM_ERROR = (-4); public const int Z_BUF_ERROR = (-5); public const int Z_VERSION_ERROR = (-6); + + /// + /// Get the zlib result name from an integer + /// + /// Integer to translate to the result name + /// Name of the result, the integer as a string otherwise + public static string ToZlibConstName(this int result) + { + return result switch + { + 0 => "Z_OK", + 1 => "Z_STREAM_END", + 2 => "Z_NEED_DICT", + + -1 => "Z_ERRNO", + -2 => "Z_STREAM_ERROR", + -3 => "Z_DATA_ERROR", + -4 => "Z_MEM_ERROR", + -5 => "Z_BUF_ERROR", + -6 => "Z_VERSION_ERROR", + + _ => result.ToString(), + }; + } } } \ No newline at end of file