Skip to content
Tcl Source Code Artifact [4be58cd530]
Login

Artifact [4be58cd530]

Artifact 4be58cd530fbeef2ac05bf1a5cd6e836847fad6ecb5fe3b229d6cc8abafce1fd:


---
CommandName: Tclzipfs
ManualSection: 3
Version: 9.0
TclPart: Tcl
TclDescription: Tcl Library Procedures
Links:
 - zipfs(n)
Keywords:
 - compress
 - filesystem
 - zip
Copyright:
 - Copyright (c) 2015 Jan Nijtmans <[email protected]>
 - Copyright (c) 2015 Christian Werner <[email protected]>
 - Copyright (c) 2017 Sean Woods <[email protected]>
---

# Name

TclZipfs\_AppHook, TclZipfs\_Mount, TclZipfs\_MountBuffer, TclZipfs\_Unmount - handle ZIP files as Tcl virtual filesystems

# Synopsis

::: {.synopsis} :::
[const char \*]{.ret} [TclZipfs\_AppHook]{.ccmd} [argcPtr, argvPtr]{.cargs}
[int]{.ret} [TclZipfs\_Mount]{.ccmd} [interp, zipname, mountpoint, password]{.cargs}
[int]{.ret} [TclZipfs\_MountBuffer]{.ccmd} [interp, data, dataLen, mountpoint, copy]{.cargs}
[int]{.ret} [TclZipfs\_Unmount]{.ccmd} [interp, mountpoint]{.cargs}
:::

# Arguments

::: {.arguments} :::

[\*argcPtr]{.carg .in type="int"}
: Pointer to a variable holding the number of command line arguments from **main**().

[\*\*\*argvPtr]{.carg .in type="char"}
: Pointer to an array of strings containing the command line arguments to **main**().

[\*interp]{.carg .in type="Tcl_Interp"}
: Interpreter in which the ZIP file system is mounted.  The interpreter's result is modified to hold the result or error message from the script.

[\*zipname]{.carg .in type="const char"}
: Name of a ZIP file. Must not be NULL when either mounting or unmounting a ZIP.

[\*mountpoint]{.carg .in type="const char"}
: Name of a mount point, which must be a legal Tcl file or directory name. May be NULL to query current mount points.

[\*password]{.carg .in type="const char"}
: An (optional) password. Use NULL if no password is wanted to read the file.

[\*data]{.carg .in type="const void"}
: A data buffer to mount. The data buffer must hold the contents of a ZIP archive, and must not be NULL.

[dataLen]{.carg .in type="size_t"}
: The number of bytes in the supplied data buffer argument, *data*.

[copy]{.carg .in type="int"}
: If non-zero, the ZIP archive in the data buffer will be internally copied before mounting, allowing the data buffer to be disposed once [TclZipfs\_MountBuffer][zipfs] returns. If zero, the caller guarantees that the buffer will be valid to read from for the duration of the mount.
:::

# Description

[TclZipfs\_AppHook][zipfs] performs all functions required to initialize Tcl for use in an application, taking into account available ZIP archives as follows:

1. If the current application executable has a mountable ZIP archive, that archive is mounted under *ZIPFS\_VOLUME***/app** as a read-only Tcl virtual file system (VFS). If the Tcl shared library has a mountable ZIP archive, that archive mounted under *ZIPFS\_VOLUME***/lib/tcl** as a read-only Tcl VFS. The value of *ZIPFS\_VOLUME* can be retrieved using the Tcl command [zipfs root][zipfs]. Both are included in the search path for locating Tcl support scripts as described in the **tcl\_library** global variable documentation.

2. If a file named **main.tcl** is located in the root directory of that file system (i.e., at *ZIPFS\_VOLUME***/app/main.tcl** after the ZIP archive is mounted as described above) it is treated as the startup script for the process.


On Windows, [TclZipfs\_AppHook][zipfs] has a slightly different signature, since it uses WCHAR instead of char. As a result, it requires the application to be compiled with the UNICODE preprocessor symbol defined (e.g., via the **-DUNICODE** compiler flag).

The result of [TclZipfs\_AppHook][zipfs] is the full Tcl version with build information (e.g., **9.0.0+abcdef...abcdef.gcc-1002**). The function *may* modify the variables pointed to by *argcPtr* and *argvPtr* to remove arguments; the current implementation does not do so, but callers *should not* assume that this will be true in the future.

[TclZipfs\_Mount][zipfs] is used to mount ZIP archives and to retrieve information about currently mounted archives. If *mountpoint* and *zipname* are both specified (i.e. non-NULL), the function mounts the ZIP archive *zipname* on the mount point given in *mountpoint*. If *password* is not NULL, it should point to the NUL terminated password protecting the archive. If not under the zipfs file system root, *mountpoint* is normalized with respect to it. For example, a mount point passed as either **mt** or **/mt** would be normalized to **//zipfs:/mt**, given that *ZIPFS\_VOLUME* as returned by [zipfs root][zipfs] is "//zipfs:/". An error is raised if the mount point includes a drive or UNC volume. On success, *interp*'s result is set to the normalized mount point path.

If *mountpoint* is a NULL pointer, information on all currently mounted ZIP file systems is stored in *interp*'s result as a sequence of mount points and ZIP file names.

If *mountpoint* is not NULL but *zipfile* is NULL, the path to the archive mounted at that mount point is stored as *interp*'s result. The function returns a standard Tcl result code.

[TclZipfs\_MountBuffer][zipfs] mounts the ZIP archive content *data* on the mount point given in *mountpoint*. Both *mountpoint* and *data* must be specified as non-NULL. The *copy* argument determines whether the buffer is internally copied before mounting or not. The ZIP archive is assumed to be not password protected. On success, *interp*'s result is set to the normalized mount point path.

**TclZipfs\_Unmount** undoes the effect of [TclZipfs\_Mount][zipfs], i.e., it unmounts the mounted ZIP file system that was mounted from *zipname* (at *mountpoint*). Errors are reported in the interpreter *interp*.  The result of this call is a standard Tcl result code.

[TclZipfs\_AppHook][zipfs] can not be used in stub-enabled extensions.


[zipfs]: zipfs.md