I need to load a large xml into Flash, and I'm trying to send it compressed. To do this, I tried zlib to compress the string and send it base64 to the encoding. In Flash, I turn a string into an array of bytes and use the uncompress () method. So far I have tried:
ZLIB.NET
byte[] bytData = System.Text.Encoding.UTF8.GetBytes(str);
MemoryStream ms = new MemoryStream();
Stream s = new zlib.ZOutputStream(ms, 3);
s.Write(bytData, 0, bytData.Length);
s.Close();
byte[] compressedData = (byte[])ms.ToArray();
return System.Convert.ToBase64String(compressedData);
Ionic.Zlib (DotNetZip)
return System.Convert.ToBase64String(Ionic.Zlib.GZipStream.CompressBuffer(System.Text.Encoding.UTF8.GetBytes(str)));
ICSharpCode.SharpZipLib (I don't know how to set compression in zlib)
byte[] a = Encoding.Default.GetBytes(str);
MemoryStream memStreamIn = new MemoryStream(a);
MemoryStream outputMemStream = new MemoryStream();
ZipOutputStream zipStream = new ZipOutputStream(outputMemStream);
zipStream.SetLevel(3);
ZipEntry newEntry = new ZipEntry("zipEntryName");
newEntry.DateTime = DateTime.Now;
zipStream.PutNextEntry(newEntry);
StreamUtils.Copy(memStreamIn, zipStream, new byte[4096]);
zipStream.CloseEntry();
zipStream.IsStreamOwner = false;
zipStream.Close();
byte[] byteArrayOut = outputMemStream.ToArray();
return System.Convert.ToBase64String(byteArrayOut);
Everyone produces different results, but flash causes error # 2058: an error occurred while unpacking the data.
var decode:ByteArray = Base64.decodeToByteArray(str);
decode.uncompress();
return decode.toString();
Base64 class from here http://code.google.com/p/as3crypto/source/browse/trunk/as3crypto/src/com/hurlant/util/Base64.as?r=3
So how can I compress a string in .net and unzip it in flash?