Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Results differ from System.IO.Compression #5

Open
Geri-Borbas opened this issue Jul 9, 2017 · 4 comments
Open

Results differ from System.IO.Compression #5

Geri-Borbas opened this issue Jul 9, 2017 · 4 comments

Comments

@Geri-Borbas
Copy link

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?

@jonathanpeppers
Copy link
Contributor

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.

@Geri-Borbas
Copy link
Author

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
Copy link
Author

Geri-Borbas commented Jul 9, 2017

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. 😄

@jonathanpeppers
Copy link
Contributor

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants