我正在尝试使用Xamarin.Forms中的SharpZipLib从HttpClient解压缩流。此代码在iOS上完美运行,但在Android上CanDecompressEntry()始终返回false。我想念的是什么?也许Android需要一些权限?
var zipStream = await httpClient.GetStreamAsync(url);
using (ZipInputStream s = new ZipInputStream(zipStream))
{
ZipEntry theEntry;
//const int size = 2048;
byte[] data = new byte[2048];
Debug.WriteLine(s.CanDecompressEntry);
while ((theEntry = s.GetNextEntry()) != null)
{
if (theEntry.IsFile)
{
string str = "";
while (true)
{
int size = s.Read(data, 0, data.Length);
if (size > 0)
{
str += new UTF8Encoding().GetString(data, 0, size);
}
else
{
files.Add(theEntry.Name.Substring(0,theEntry.Name.Length-5), str);
break;
}
}
}
}
}
return files;
好我只是将ConfigureAwait设置为false,它可以工作。
var zipStream = await httpClient.GetStreamAsync(url).ConfigureAwait(false);