适用于 Windows Phone 7 的 Zip 库

适用于 Windows Phone 7 的 Zip 库

问题描述:

我正在下载 zip 文件并将它们放在 Windows Phone 7 上的独立存储中.是否有允许我解压缩文件的 API 或库?

I'm downloading zip files and place them in isolated storage on Windows Phone 7. Is there an API or library that allows me to unzip the files?

您可以使用 SharpZipLib 解压缩下载的 zip 文件.我在我的应用程序中使用了这个版本(从 Codeplex 下载的二进制文件),没有任何问题,但是,我建议下载源代码并自己编译.解压后的文件可以读入字符串 -

You can use SharpZipLib to decompress downloaded zip files. I have used this version (binaries downloaded from Codeplex) in my applications without any issues, however, I would recommend download the source and compiling it yourself. The decompressed file can be read into a string -

// check for magic numbers
if (data.Length > 2 && (data[0] == 31 && data[1] == 139))
{
   using (var ms = new MemoryStream(data))
   using (var gzip = new GZipInputStream(ms))
   using (var reader = new StreamReader(gzip))
   {
      fileContents = reader.ReadToEnd();
   }
}         

data 是一个字节数组,用于保存从 IndependentStorage 读取的 zip 文件.fileContents 是一个保存解压文件内容的字符串.

data is an array of bytes which holds the zip file read from IsolatedStorage. fileContents is a string that holds the contents of the decompressed file.

HTH,indyfromoz

HTH, indyfromoz