gpt4 book ai didi

.net - 如何在 .net c# 中压缩字符串并在 flash as3 中解压缩?

转载 作者:行者123 更新时间:2023-12-01 19:36:53 24 4
gpt4 key购买 nike

我必须在 flash 中加载一个大的 xml,并且我正在尝试将其压缩后发送。为此,我尝试使用 zlib 压缩字符串并将其以 base64 编码发送。在 flash 中,我将字符串转换为字节数组并使用其 uncompress() 方法。到目前为止我试过:

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(不知道怎么设置压缩为zlib)

byte[] a = Encoding.Default.GetBytes(str);
MemoryStream memStreamIn = new MemoryStream(a);
MemoryStream outputMemStream = new MemoryStream();
ZipOutputStream zipStream = new ZipOutputStream(outputMemStream);
zipStream.SetLevel(3); //0-9, 9 being the highest level of compression
ZipEntry newEntry = new ZipEntry("zipEntryName");
newEntry.DateTime = DateTime.Now;
zipStream.PutNextEntry(newEntry);
StreamUtils.Copy(memStreamIn, zipStream, new byte[4096]);
zipStream.CloseEntry();
zipStream.IsStreamOwner = false; // False stops the Close also Closing the underlying stream.
zipStream.Close(); // Must finish the ZipOutputStream before using outputMemStream.
byte[] byteArrayOut = outputMemStream.ToArray();
return System.Convert.ToBase64String(byteArrayOut);

所有这些都会产生不同的结果,但闪存会抛出错误 #2058:解压缩数据时出错。

var decode:ByteArray = Base64.decodeToByteArray(str);
decode.uncompress();
return decode.toString();

Base64 类来自这里 http://code.google.com/p/as3crypto/source/browse/trunk/as3crypto/src/com/hurlant/util/Base64.as?r=3

那么,我如何在 .net 中压缩一个字符串并在 flash 中解压它呢?

最佳答案

我让它与 ZLIB.NET 一起工作。我只需要将编码设置为 ASCII Encoding.ASCII.GetBytes(str);

关于.net - 如何在 .net c# 中压缩字符串并在 flash as3 中解压缩?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3102402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com