# (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)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line"> \
\&#xNAN;**(make-zip-archive&#x20;*****bvec*****)**\
**(make-zip-archive&#x20;*****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&#x20;*****path*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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

**(open-zip-archive&#x20;*****path*****)**   <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(open-zip-archive&#x20;*****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?&#x20;*****obj*****)**   <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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

**(zip-archive-mutable?&#x20;*****archive*****)**   <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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

**(zip-archive-path&#x20;*****archive*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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&#x20;*****archive*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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&#x20;*****archive*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns the number of entries in *archive*.

**(zip-entries&#x20;*****archive*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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

**(zip-entry-exists?&#x20;*****archive path*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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

**(zip-entry-compressed?&#x20;*****archive path*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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?&#x20;*****archive path*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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?&#x20;*****archive path*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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?&#x20;*****archive path*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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&#x20;*****archive path*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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&#x20;*****archive path*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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&#x20;*****archive path base*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(add-zip-entry&#x20;*****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&#x20;*****archive path bvec*****)**   <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(write-zip-entry&#x20;*****archive path bvec compressed?*****)**\
\&#xNAN;**(write-zip-entry&#x20;*****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&#x20;*****archive path*****)**   <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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&#x20;*****archive path base*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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

**(read-zip-entry&#x20;*****archive path*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.lisppad.app/libraries/lispkit/lispkit-archive-zip.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
