PackageDescription: Compression-Zip


Compression - Zip

Last published: April 1, 2013 by 'nross'

Defines 7 Classes
Extends 7 Classes


Provides facilities for reading file archives in 'zip' format (http://www.pkware.com/documents/casestudies/APPNOTE.TXT) that have been compressed using the 'deflate' method (generally the default). An archive is represented by an instance of Archive containing a collection of ArchiveEntries describing the compressed files. In general the contents of a file can be accessed through a decompression stream. The right kind of stream can be obtained from an ArchiveEntry using the #readStream message. Archives, entries and decompression streams also have potentially interesting attributes associated with them, for example #compressedSize, #uncompressedSize, #fileName, #lastModificationDate/Time, etc. See the 'accessing' protocol on corresponding classes for a full list of available attributes.

Here is an example of how to get contents of all files in an archive:

archive := OS.Zip.Archive filename: 'archive.zip'.
[ archive entries collect: [ :each | each contents ] ] ensure: [ archive close ]

Here is how to access contents of the last file in an archive as a stream:

archive := OS.Zip.Archive filename: 'archive.zip'.
[ archive entries last readStream upToEnd ] ensure: [ archive close ]

Both archives and entries understand message #extractTo: which takes a directory (String or Filename) as an argument, and extract the entire contents of the receiver into that directory.

(OS.Zip.Archive filename: 'archive.zip') extractTo: '.' "The archive is closed automatically."

archive := OS.Zip.Archive filename: 'archive.zip'.
[ archive entries last extractTo: '.' ] ensure: [ archive close ]

The directory structures embedded in the archive will be respected and reconstructed as needed.

LIMITATIONS:
- only the basic (commonly used) archiving capabilities are supported, none of the extended features like 64-bit extensions, encryption, multiple volumes, etc are available