Unity.IO.Compression icon indicating copy to clipboard operation
Unity.IO.Compression copied to clipboard

Results differ from System.IO.Compression

Open Geri-Borbas opened this issue 8 years ago • 4 comments

Hi, I tried the library, but the results differs from System.IO.Compression when using GZipStream.

Test string: Some test string to compress. Result using System.IO: H4sIAAAAAAAAAwvOz01VKEktLlEoLinKzEtXKMlXSM7PLShKLS7WAwAr6BTWHQAAAA== Result using Unity.IO: H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt/SvVK1+B0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee++999577733ujudTif33/8/XGZkAWz2zkrayZ4hgKrIHz9+fB 8/Il5Xizxt86ZNm7YulhdpW6XTarGq86YZ/z8BAAD//yvoFNYdAAAA

Only the former is recognizable by other gzip libraries. See this fiddle: http://jsfiddle.net/9yH7M/837/ Or: http://www.txtwizard.net/compression

Is there some defaults that has been tweaked? Could you shed a light on what is happening here?

Geri-Borbas avatar Jul 09 '17 00:07 Geri-Borbas

Can you post a code example of your C#?

I did this maybe two years ago... only thing I remember taking out was a call to a zlib native library that would not work cross platform, so it is an all C# implementation.

I would try changing the compression level, if that is an option.

jonathanpeppers avatar Jul 09 '17 01:07 jonathanpeppers

Thanks, I changed (hard coded) the default compression level in the library, but still, Unity.IO gave that longish result.

Just made a string extension method.

public static string Zip(this string this_)
{
	byte[] encoded = Encoding.UTF8.GetBytes(this_);
	byte[] compressed = CompressBytes(encoded);
	return Convert.ToBase64String(compressed);
}

static byte[] CompressBytes(byte[] input)
{
	using (MemoryStream outputStream = new MemoryStream())
	{
		using (GZipStream zipStream = new GZipStream(outputStream, CompressionMode.Compress))
		{
			zipStream.Write(input, 0, input.Length);
			zipStream.Flush();

		}
		return outputStream.ToArray();
	}
}

And test it like below (asserting the output I got from other libraries).

original = "Some test string to compress.";
assertation = "H4sIAAAAAAAAAwvOz01VKEktLlEoLinKzEtXKMlXSM7PLShKLS7WAwAr6BTWHQAAAA==";
result = original.Zip();
Assert.AreEqual(assertation, result);

The assertation works using System.IO, but is the one I posted above using Unity.IO.

Geri-Borbas avatar Jul 09 '17 13:07 Geri-Borbas

Anyway, in Unity 5.5 they included GZipStream in the Mono installation. 🎉

See issue 569612 on 5.5.0f3 Release Notes.

Editor: Add support for the GZipStream class in the editor and standalone players. (569612)

So apparently I just don't need this library, you may update README.md and stop answering here folks like me. 😄

Geri-Borbas avatar Jul 09 '17 13:07 Geri-Borbas

Sorry, I don't have access to this repo any longer since I do not work for Hitcents. I suspect this project will be abandoned.

I don't have a way to update the README...

jonathanpeppers avatar Aug 03 '17 14:08 jonathanpeppers