我正在为 Windows 8 构建一个 Metro 风格的应用程序,我有一个从 Web 服务下载的 zip 文件,我想解压它。
我已经看到了压缩和解压缩的示例,但这需要单个文件来压缩/解压缩它。我有一个需要提取的完整目录结构。
这是我到目前为止所拥有的:
var appData = ApplicationData.Current;
var file = await appData.LocalFolder.GetItemAsync("thezip.zip") as StorageFile;
var decompressedFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("tempFileName", CreationCollisionOption.GenerateUniqueName);
using (var decompressor = new Decompressor(await file.OpenSequentialReadAsync()))
using (var decompressedOutput = await decompressedFile.OpenAsync(FileAccessMode.ReadWrite))
{
var bytesDecompressed = await RandomAccessStream.CopyAsync(decompressor, decompressedOutput);
}
但这并不好,bytesDecompressed
变量大小始终为零,但 zip 文件为 1.2MB
任何帮助将不胜感激。
编辑:回答,感谢Mahantesh
这是解压文件的代码:
private async void UnZipFile()
{
var folder = ApplicationData.Current.LocalFolder;
using (var zipStream = await folder.OpenStreamForReadAsync("thezip.zip"))
{
using (MemoryStream zipMemoryStream = new MemoryStream((int)zipStream.Length))
{
await zipStream.CopyToAsync(zipMemoryStream);
using (var archive = new ZipArchive(zipMemoryStream, ZipArchiveMode.Read))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.Name != "")
{
using (Stream fileData = entry.Open())
{
StorageFile outputFile = await folder.CreateFileAsync(entry.Name, CreationCollisionOption.ReplaceExisting);
using (Stream outputFileStream = await outputFile.OpenStreamForWriteAsync())
{
await fileData.CopyToAsync(outputFileStream);
await outputFileStream.FlushAsync();
}
}
}
}
}
}
}
}
在 Metro 风格应用程序中,您可以使用 ZipArchive、ZipArchiveEntry、DeflateStream 和 GZipStream 类中的方法来处理压缩文件。
Refer : 在 Metro 中解压文件 https://stackoverflow.com/questions/10547361/how-to-decompress-a-zip-file-in-windows-8-metro-without-ziparchive-zlib-net
Refer : Metro C# 中的文件夹 zip/unzip http://roboshashi.blogspot.in/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)