Evaluators (CanDecode & CompressionRatio)
Hello there,
Cool project. I was wondering about the option of adding a bool for a byte[] bool = SmazSharp.CanDecode(input byte[]), and a compression ratio value. int ratio = SmazSharp.CompressionRatio(string input)
Thanks Dave
Hi Dave, Thanks for your feedback.
Both of those suggestions would largely involve performing the actual compression/decompression. Presumably (depending on the output), you might then choose to perform the operation (or not?). It might be best to perform the compression/decompression and calculate the ratio yourself (as its meaning is a little complicated - see below).
While the source hasn't been optimised for allocations, it should be possible to have an allocation-free ratio calculator (if that's what you're worried about):
int SmazSharp.CalculateCompressedSize(string Input)
float SmazSharp.CalculateCompressedRatio(string Input)
and then:
int SmazSharp.CalculateDecompressedSize(byte[] Input)
This is slightly complicated, as the string type in .Net is in Unicode encoding, but Smaz only compresses ASCII. Should the ratio be compared to an ASCII encoded string, or it's Unicode? Is the size equal to the number of characters in the string, or the number of bytes it occupies?
Regarding, the SmazSharp.CanDecode suggestion, how do you feel about the try pattern? For example:
bool SmazSharp.TryDecompress(byte[] Input, out string Output)
Gary
Thank you, thank you! Long circle back here, but did some initial experimentation and wow. This is so slick code. Thank you!