如何在 C# 中将 .zip 文件视为目录?

发布于 2024-08-30 05:33:25 字数 60 浏览 5 评论 0原文

我希望能够读取 zip 文件中的文件,就像读取物理文件夹中的文件一样。如何在不解压文件的情况下执行此操作?

I want to be able to be able to read files in zip files just as I would read files in a physical folder. How can I do this without having to extract the files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

漫雪独思 2024-09-06 05:33:25

有一些组件允许您从 .NET 应用程序查看 .zip 文件的内容:

我以前使用过#ziplib,它对于我的目的来说工作得很好,但不是太广泛。

There are some components out there that allow you to view the contents of a .zip file from your .NET application:

I've used the #ziplib before and it worked fine for my purposes which weren't too extensive.

誰認得朕 2024-09-06 05:33:25

我最近开源了我的 Platform.VirtualFileSystem C# 库。

https://github.com/platformdotnet/Platform.VirtualFileSystem
https://github.com/platformdotnet/Platform.VirtualFileSystem/wiki

您可以阅读 zip像这样的文件:

var directory = FileSystemManager.Default.ResolveDirectory("zip://[file:///c:/test.zip]/");
directory.GetFiles().ForEach(Console.WriteLine);

它可以从 NuGet 获得: http://nuget.org/packages/Platform .VirtualFileSystem.Providers.Zip/

I recently opened sourced my Platform.VirtualFileSystem C# library.

https://github.com/platformdotnet/Platform.VirtualFileSystem
https://github.com/platformdotnet/Platform.VirtualFileSystem/wiki

You can read zip files like this:

var directory = FileSystemManager.Default.ResolveDirectory("zip://[file:///c:/test.zip]/");
directory.GetFiles().ForEach(Console.WriteLine);

It's available from NuGet: http://nuget.org/packages/Platform.VirtualFileSystem.Providers.Zip/

败给现实 2024-09-06 05:33:25

首先.NET虽然支持压缩文件但不支持ZIP文件(不确定.NET v4)

无论如何我使用SharpZipLib
http://www.icsharpcode.net/OpenSource/SharpZipLib/(GPL +例外读取小心)

该库允许您浏览 ZipStream 并访问 ZipEntry,它为您提供所有文件信息。

请记住,在压缩所需文件时,如果压缩文件夹,第一个条目将是该文件夹。不是问题,但如果您希望有一个清晰的列表,请压缩它而不包含文件夹路径。

还支持密码 zip。

First of all .NET although it supports compressed files it does not support ZIP files (not sure about .NET v4)

Anyhow I used SharpZipLib
http://www.icsharpcode.net/OpenSource/SharpZipLib/ (GPL +exceptions read carefully)

This library allows you to go through the ZipStream and get access to the ZipEntry which gives you all the file information.

Have in mind that when compressing the files you want, if you compress a folder the first entry will be that folder. Not a problem, but if you wish to have a clear list, zip it without folders paths.

Also supports passworded zips.

甜心小果奶 2024-09-06 05:33:25

您将需要编写或找到一个将自身呈现为虚拟文件系统的包装器。

API 可以像单个 public Stream GetFile(string path) 方法一样简单,也可以像完整的 FS 一样复杂。

使用任何支持您想要使用的文件格式的压缩库都可以实现这一点。

我使用 Cheeso's DotNetZip 库,它工作得很好。

You will need to write or find a wrapper that presents itself as a virtual file system.

The api could be as simple as a singe public Stream GetFile(string path) method or as complex as a full FS.

This is possible using any compression lib that supports the file format you would like to use.

I have written a simple compressed VFS using Cheeso's DotNetZip library and it works just fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文