当我使用SharpZipLib解压缩在Windows Phone 7上有5000个文件的zip文件时。完成它需要5分钟以上。 这是代码:
using (StreamReader httpwebStreamReader = new StreamReader(ea.Result))
{
//open isolated storage to save files
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (ZipInputStream s = new ZipInputStream(httpwebStreamReader.BaseStream))
{
//s.Password = "123456";//if archive is encrypted
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
// create directory
if (directoryName.Length > 0)
{
isoStore.CreateDirectory(directoryName);
}
if (fileName != String.Empty)
{
//save file to isolated storage
using (BinaryWriter streamWriter =
new BinaryWriter(new IsolatedStorageFileStream(theEntry.Name,
FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write, isoStore)))
{
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
}
}
}
}
}
}
为什么这么慢? 如何加快解压缩操作? 有人知道吗?
答案 0 :(得分:0)
我认为您需要增加缓冲区大小。改变行
int size = 2048;
byte[] data = new byte[2048];
将2048
更改为32768
(32 * 1024)。
2KB的块大小正在对闪存存储进行大量的单独写入。根据我的经验,这是一个有点慢的事情,可能因设备而异。一个32KB的块大小应该减少16倍,但我不知道这是否会导致16倍的直接加速。我很想回复。