2

当我使用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;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

为什么这么慢?如何加快解压缩操作?有谁知道?

4

1 回答 1

0

我认为您需要增加缓冲区大小。换行

int size = 2048;
byte[] data = new byte[2048];

并将其更改为(32 * 1024)之2048类的东西。32768

2KB 的块大小正在对闪存进行大量单独写入。以我的经验,这是一件有点慢的事情,并且可能因设备而异。32KB 的块大小应该减少 16 倍,但我不知道这是否会导致直接 16 倍的加速。我有兴趣听到回音。

于 2012-07-30T10:57:02.447 回答