Port extension code for zlib constant names from UnshieldSharp

This commit is contained in:
Matt Nadareski
2024-04-24 00:49:34 -04:00
parent ae223a4589
commit bc06cb5bdb

View File

@@ -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);
/// <summary>
/// Get the zlib result name from an integer
/// </summary>
/// <param name="result">Integer to translate to the result name</param>
/// <returns>Name of the result, the integer as a string otherwise</returns>
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(),
};
}
}
}