Lui14
May 14, 2014, 2:36pm
1
I need to compress (zip or any other way is ok) a string, send it to a php’s page so that it is saved on the server and to do that another client can download and decompress it. Do you know if there are some example/library or another thing to compress/decompress in c# with Unity?
I need it for webplayer, so I can’t use filesystem.
Is System.IO.Compression not available in webplayer or something?
It’s not necessarily filesystem.
Here’s a stack overflow thread on it:
http://stackoverflow.com/questions/7343465/compression-decompression-string-with-c-sharp
You could also write your own if that doesn’t work.
Here’s one in C:
Lui14
May 14, 2014, 2:58pm
4
I tried 2 different systems from your first link, but I have this error:
DllNotFoundException: MonoPosixHelper
System.IO.Compression.DeflateStream…ctor (System.IO.Stream compressedStream, CompressionMode mode, Boolean leaveOpen, Boolean gzip)
(wrapper remoting-invoke-with-check) System.IO.Compression.DeflateStream:.ctor (System.IO.Stream,System.IO.Compression.CompressionMode,bool,bool)
System.IO.Compression.GZipStream…ctor (System.IO.Stream compressedStream, CompressionMode mode, Boolean leaveOpen)
System.IO.Compression.GZipStream…ctor (System.IO.Stream compressedStream, CompressionMode mode)
(wrapper remoting-invoke-with-check) System.IO.Compression.GZipStream:.ctor (System.IO.Stream,System.IO.Compression.CompressionMode)
Generale.Zip (System.String str) (at Assets/Generale.cs:113)
Generale+c__Iterator1.MoveNext () (at Assets/Generale.cs:40)
Lui14
May 14, 2014, 3:08pm
5
Thank you. It seems to be perfect as system but I need to transform in string in order to send to php. In this case I have a byte [ ]. How can I transform all without any problem?
You can convert the string to a byte array: System.Text.Encoding.UTF8.GetBytes (myString);
–Eric
Lui14
May 14, 2014, 4:04pm
7
I have a problem, I use this:
void Start3()
{
string longstring = “defined input is deluciously delicious.14 And here and Nora called The reversal from ground from here and executed with touch the country road, Nora made of, reliance on, can’t publish the goals of grandeur, said to his book and encouraging an envelope, and enable entry into the chryssial shimmering of hers, so God of information in her hands Spiros sits down the sign of winter? —It’s kind of Spice Christ. It is one hundred birds circle above the text: They did we said. 69 percent dead. Sissy Cogan’s shadow. —Are you x then sings.) I’m 96 percent dead humanoid figure,”;
// Compress
byte[ ] mybyte = Encoding.ASCII.GetBytes(longstring);
byte[ ] compressed2 = CLZF2.Compress(mybyte);
// Send to PHP for another client
string php_string = Encoding.UTF8.GetString(compressed2, 0, compressed2.Length);
// …
// SEND PHP TO STRING
// …
// The client recover the compressed string
compressed2 = System.Text.Encoding.UTF8.GetBytes (php_string);
//
byte[ ] decompressed = CLZF2.Decompress(compressed2);
string final_string = Encoding.UTF8.GetString(decompressed, 0, decompressed.Length);
//
Debug.Log ("Inizial value => "+longstring);
Debug.Log ("End value => "+final_string);
}
Error: