(lispkit archive zip)

Library (lispkit archive zip) provides an API for creating and managing zip archives. Zip archives are either persisted on the file system, or they are created in-memory. Zip archives can be opened either in read-only or read-write mode. They allow either files or in-memory data (in the form of bytevectors) to be included. Such zip entries are either a file, a directory, or a symbolic link. In an archive, files are stored in either compressed or uncompressed form.

Constructors

(make-zip-archive) (make-zip-archive bvec) (make-zip-archive bvec mutable?)

Procedure make-zip-archive creates an in-memory zip archive. If bytevector bvec is provided, the zip archive is created from the given binary data, otherwise, a new empty zip archive is returned. For a zip archive created from a bytevector, parameter mutable? determines if it is a read-only or read-write zip archive. In the latter case, mutable? has to be set to #t, the default is #f.

(create-zip-archive path)

Creates a new empty read-write zip archive at the given file path.

(open-zip-archive path) (open-zip-archive path mutable?)

Opens a zip archive at the given file path. By default, the zip archive is opened in read-only mode, unless mutable? is set to #t.

Properties of archives

(zip-archive? obj)

Returns #t if obj refers to a zip archive, otherwise #f is being returned.

(zip-archive-mutable? archive)

Returns #t if the given zip archive is mutable, i.e. opened in read-write mode, #f otherwise.

(zip-archive-path archive)

Procedure zip-archive-path returns the file path at which archive is being persisted. If archive is a in-memory zip archive, then #f is returned.

(zip-archive-bytevector archive)

Procedure zip-archive-bytevector returns archive as a bytevector. This bytevector can be written to disk or used to create a in-memory copy of the zip archive.

Introspecting entries

Entries in zip archives are referred to via their relative file path in the archive. All procedures that provide information about a zip archive entry therefore expect two arguments: the zip archive and a file path.

(zip-entry-count archive)

Returns the number of entries in archive.

(zip-entries archive)

Returns a list of file paths for all entries of zip archive archive.

(zip-entry-exists? archive path)

Returns #t if archive contains an entry with the given file path.

(zip-entry-compressed? archive path)

Returns #t if archive contains an entry for the given file path and this entry is stored in compressed form. If path does not refer to a valid entry in archive, the procedure zip-entry-compressed? fails with an error.

(zip-entry-file? archive path)

Returns #t if archive contains an entry for the given file path and this entry is a file. If path does not refer to a valid entry in archive, the procedure zip-entry-file? fails with an error.

(zip-entry-directory? archive path)

Returns #t if archive contains an entry for the given file path and this entry is a directory. If path does not refer to a valid entry in archive, the procedure zip-entry-directory? fails with an error.

(zip-entry-symlink? archive path)

Returns #t if archive contains an entry for the given file path and this entry is a symbolic link. If path does not refer to a valid entry in archive, the procedure zip-entry-directory? fails with an error.

(zip-entry-compressed-size archive path)

Returns the size of the compressed file for the entry at the given path in bytes. If path does not refer to a valid entry in archive, the procedure zip-entry-compressed-size fails with an error.

(zip-entry-uncompressed-size archive path)

Returns the size of the uncompressed file for the entry at the given path in bytes. If path does not refer to a valid entry in archive, the procedure zip-entry-uncompressed-size fails with an error.

Adding and removing entries

(add-zip-entry archive path base) (add-zip-entry archive path base compressed?)

Adds the file, directory, or symbolic link at path relative to path base to the given zip archive. The corresponding entry in archive is identified via path. The file is stored in uncompressed form if compressed? is set to #f. The default for compressed? is #t.

(write-zip-entry archive path bvec) (write-zip-entry archive path bvec compressed?) (write-zip-entry archive path bvec compressed? time)

Adds a new file entry to archive at path based on the content of bytevector bvec. The entry is stored in uncompressed form if compressed? is set to #f. The default for compressed? is #t. time is a date-time object as defined by library (lispkit date-time) which defines the modification time of the new entry.

(delete-zip-entry archive path)

Deletes the entry at path from archive. Procedure delete-zip-entry fails if the entry does not exist or if the archive is opened in read-only mode.

Extracting entries

(extract-zip-entry archive path base)

Extracts the entry at path in archive and stores it on the file system at path relative to path base.

(read-zip-entry archive path)

Returns the file entry at path in archive in form of a bytevector. Procedure read-zip-entry fails if the entry does not exist or if the entry is not a file entry.

Last updated