Did you know ... Search Documentation:
zip.pl -- Access resource ZIP archives
PublicShow source

This library provides access to ZIP files. ZIP files are used to store SWI-Prolog resources. Ths library provides more high level access and documentation in addition to the low level access provided as built in as it is needed to bootstrap SWI-Prolog.

Access to a zip file is provided by means of a zipper object. This is a blob that is subject to atom garbage collection. Collecting a zipper closes the underlying OS access.

A zipper is a stateful object. We recognise the following states: idle, scan, read_entry, write_entry and close. The interface raise a permission_error when trying to make an illegal state transition.

Being stateful, a zipper cannot be used simultaneously from multiple threads. The zipper becomes owned by a thread when moving to scan using zipper_goto/2. It is released after zipper_open_current/3 followed by closing the stream.

Source zip_open(+File, +Mode, -Zipper, +Options) is det
Create a Zipper, providing access to File. Mode is one of read or write. The Options list is currently ignored.
Source zip_close(+Zipper) is det
Source zip_close(+Zipper, +Options) is det
Close a zipper. Options processed:
comment(+Comment)
If the zipper is open for writing, set the global comment for the zip file.
 zipper_goto(+Zipper, +Where) is semidet
Seek Zipper to a specified entry. Where is one of
first
Go to the first entry. Fails if the zip is empty.
next
Go to the next entry. Fails if there is no next entry.
file(Name)
Go to the entry with the specified name.
 zipper_open_current(+Zipper, -Stream, +Options) is det
Open the current entry as an input stream. Before this call the caller must use zipper_goto/2 to position to archive. Options:
type(+Type)
encoding(+Encoding)
bom(+Boolean)
Determine type and encoding of the stream. The semantics is the same as for open/4.
release(+Boolean)
If true (default), release te archive for access by other threads after the entry is closed.

It is allowed to call zip_close/1 immediately after this call, in which case the archive is closed when the entry is closed.

Source with_zipper(+Zipper, :Goal)
Run Goal while holding ownership over Zipper.
Source zipper_file_info(+Zipper, -Name, -Attrs) is det
Obtain information about the current zip entry. Name is an atom representing the name of the entry. Attrs is a dict holding:
compressed_size:Bytes
Size in the archive
uncompressed_size:Bytes
Bytes after decompression
time:Stamp
Numeric time stamp in Prolog native format (float expressing seconds since Jan 1, 1970). Note that the resolution of time in zip archives is one second.
extra:Extra
comment:Extra
Optional additional fields.
offset:Offset
Direct pointer to this entry. May be used with zip_goto/2.
Source zip_close(+Zipper) is det
Source zip_close(+Zipper, +Options) is det
Close a zipper. Options processed:
comment(+Comment)
If the zipper is open for writing, set the global comment for the zip file.

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

Source zipper_members(Arg1, Arg2)
 zipper_open_new_file_in_zip(Arg1, Arg2, Arg3, Arg4)