views:

355

answers:

6

Are there any libraries for dealing with zip files as if they were simply directories? i.e. get a file listing, read a file, etc.

I prefer something in C, but any other language is fine.

Also, it would help if such a library could deal with other compression formats (rar, 7z, etc).

+2  A: 

There is SharpZipLib, available for c#.

RedFilter
+3  A: 

Python standard library to the rescue (slightly modified from here):

>>> import zipfile
>>> z = zipfile.ZipFile('/path/to/zip/file.zip', 'r')
>>> for filename in z.namelist():
...   print filename
...   bytes = z.read(filename)
...   print len(bytes)
file/1.dat
75776
file/2.dat
38912
file/3.dat
40960
Adam Bernier
Thanks! This is awesome. I love python =D
hasen j
+1  A: 

For Java, you may consider TrueZIP, which, regarding "dealing with zip files as if they were simply directories":

  • Browse archive files using the drop-in replacements for JFileChooser and FileSystemView.
  • Browse and edit the file system with a custom JTree, including archive file up to any nesting level.

For "other compression formats", the docs say "TrueZIP ships with archive drivers for ZIP, TAR and all derivatives (JAR, TAR.GZ, TAR.BZ2, TZP, ...)." No rar that I know of.

It has an (open source) Apache license.

Glenn
+2  A: 

If you prefer C, check out Minizip. It is based on Zlib. It can open .zip files, iterate over the items, and extract files. I don't think it supports other formats.

Dani van der Meer
+2  A: 

Another option for Java is the Apache Commons VFS project.

From the site:

Commons VFS provides a single API for accessing various different file systems. It presents a uniform view of the files from various different sources, such as the files on local disk, on an HTTP server, or inside a Zip archive.

Some of the features of Commons VFS are:

  • A single consistent API for accessing files of different types.
  • Support for numerous file system types .
  • Caching of file information. Caches information in-JVM, and optionally can cache remote file information on the local file system.
  • Event delivery.
  • Support for logical file systems made up of files from various different file systems.
  • Utilities for integrating Commons VFS into applications, such as a VFS-aware ClassLoader and URLStreamHandlerFactory.
  • A set of VFS-enabled Ant tasks .
Elijah
Unfortunately Commons VFS is read-only with zip files, according to http://commons.apache.org/vfs/filesystems.html#Zip,%20Jar%20and%20Tar.
Glenn
+1  A: 

This article describes doing just such a thing - treating a zip file as an extension to the file system. It is in C#. Uses DotNetZip.

Cheeso