I would recommend breaking this single class into several classes. Generally speaking, static utility classes break a lot of rules, not the least of which is Separation of Concerns. While yes, all of the methods in this class deal with compression, they are concerned with compressing different things. Some compress byte arrays, some compress strings, some compress files. I would break this single utility into multiple utilities:
public static class ByteCompression
{
public static Byte[] Compress(Byte[] input);
public static Byte[] Compress(Byte[] input, Format format);
public static Byte[] Compress(Byte[] input, Format format, Level level);
public static Byte[] Decompress(Byte[] input);
public static Byte[] Decompress(Byte[] input, Format format);
}
public static class StringCompression
public static String Compress(String input);
public static String Compress(String input, Format format);
public static String Compress(String input, Format format, Level level);
public static String Decompress(String input);
public static String Decompress(String input, Format format);
}
public static class FileCompression
{
public static void Compress(String input_file_path, String output_file_path);
public static void Compress(String input_file_path, String output_file_path, Format format);
public static void Compress(String input_file_path, String output_file_path, Format format, Level level);
public static void Decompress(String input_file_path, String output_file_path);
public static void Decompress(String input_file_path, String output_file_path, Format format);
}
public static FolderCompression
{
public static void Compress(String input_folder_path, String output_file_path);
public static void Compress(String input_folder_path, String output_file_path, Format format);
public static void Compress(String input_folder_path, String output_file_path, Format format, Level level);
public static void Decompress(String input_file_path, String output_file_path);
public static void Decompress(String input_file_path, String output_file_path, Format format);
}
The above utility classes reduce repetition, better encapsulate purpose, are more cohesive with their member methods, and are clearer in intent. You do have four static utility types rather than one, but you aren't breaking as many rules/best practices this way. Try to avoid monolithic, do-everything utility classes. If you can, find a way to make them instance classes rather than static classes, especially if there is any shared data at the class level that is used across each compress/decompress method. That will improve thread safety.
EDIT:
A more ideal implementation would use extension methods, as andy commented. The File and Folder compression are a bit more difficult to implement as extensions, but I've tried my hand. The following examples better achieve what I was aiming for: separation of noun (or subject) from verb (or operation), providing a cleaner API that ultimately has less repetition, maintains separation of concerns, and is properly encapsulated.
public static class ByteCompressionExtensions
{
public static byte[] Compress(this byte[] input);
public static byte[] Compress(this byte[] input, Format format);
public static byte[] Compress(this byte[] input, Format format, Level level);
public static byte[] Decompress(this byte[] input);
public static byte[] Decompress(this byte[] input, Format format);
}
// In use:
byte[] myArray = new byte[] { ... };
byte[] compArray = myArray.Compress();
// Subject (noun) -----^ ^----- Operation (verb)
public static class StringCompressionExtensions
{
public static byte[] Compress(this string input);
public static byte[] Compress(this string input, Format format);
public static byte[] Compress(this string input, Format format, Level level);
// Extension method fail!! :( :( This conflicts with Decompress from the class above!
public static string Decompress(this byte[] input);
public static string Decompress(this byte[] input, Format format);
}
// In use:
string myStr = "A string!";
byte[] compArray = myStr.Compress();
// Subject (noun) ---^ ^----- Operation (verb)
myStr = compArray.Decompress(); // Fail! :(
public static class FileCompressionExtensions
{
public static void Compress(this FileInfo input, FileInfo output);
public static void Compress(this FileInfo input, FileInfo output, Format format);
public static void Compress(this FileInfo input, FileInfo output, Format format, Level level);
public static void Decompress(this FileInfo input, FileInfo output);
public static void Decompress(this FileInfo input, FileInfo output, Format format);
}
// In use:
FileInfo myFile = new FileInfo(input_file_path);
FileInfo myCompFile = new FileInfo(output_file_path);
myFile.Compress(myCompFile);
// Subject (noun) --^ ^----- Operation (verb)
myCompFile.Decompress(myFile);
public static class FolderCompressionExtensions
{
public static void Compress(this DirectoryInfo input, DirectoryInfo output);
public static void Compress(this DirectoryInfo input, DirectoryInfo output, Format format);
public static void Compress(this DirectoryInfo input, DirectoryInfo output, Format format, Level level);
public static void Decompress(this DirectoryInfo input, DirectoryInfo output);
public static void Decompress(this DirectoryInfo input, DirectoryInfo output, Format format);
}
// In use:
DirectoryInfo myDir = new DirectoryInfo(input_folder_path);
DirectoryInfo myCompDir = new DirectoryInfo(output_folder_path);
myDir.Compress(myCompDir);
// Subject (noun) --^ ^----- Operation (verb)
myCompDir.Decompress(myDir);