在C#中,我使用下面的函数压缩一个大字符串(1.20 MB),然后通过WebClient将其发布到我服务器上的php页面:
public static string Compress(string s)
{
var bytes = Encoding.Unicode.GetBytes(s);
using (var msi = new MemoryStream(bytes))
using (var mso = new MemoryStream())
{
using (var gs = new GZipStream(mso, CompressionMode.Compress))
{
msi.CopyTo(gs);
}
return Convert.ToBase64String(mso.ToArray());
}
}
基本上在C#中,我会执行以下操作来解压缩它:
public static string Decompress(string s)
{
var bytes = Convert.FromBase64String(s);
using (var msi = new MemoryStream(bytes))
using (var mso = new MemoryStream())
{
using (var gs = new GZipStream(msi, CompressionMode.Decompress))
{
gs.CopyTo(mso);
}
return Encoding.Unicode.GetString(mso.ToArray());
}
}
但我怎样才能在PHP中解压缩(解压缩字符串)