开发者

How to treat .zip files as directories in C#?

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?


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

  • http://www.icsharpcode.net/opensource/sharpziplib/ - (free open source)
  • http://xceed.com/Zip_Net_Intro.html - (commercial)

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


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/


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜