▼ |  | File: Racket File and Format Libraries

1 | Convertible: Data-Conversion Protocol
2 | gzip Compression and File Creation
3 | gzip Decompression
4 | zip File Creation
5 | zip File Extraction
6 | tar File Creation
7 | tar File Extraction
8 | tar+gzip File Extraction
9 | MD5 Message Digest
10 | SHA1 Message Digest
11 | GIF File Writing
12 | ICO File Reading and Writing
13 | Windows Registry
14 | Caching
15 | Globbing
| Bibliography
| Index

On this page:

zip
zip->output
zip-verbose

top ← prev up next →

### 4`` zip File Creation

(require file/zip) | package: base

The file/zip library provides utilities to create zip archive files, which are compatible with both Windows and Unix (including Mac OS) unpacking. The actual compression is implemented by deflate.

> > procedure

> > (zip |  | zip-file |  |  |  |
> > |  | path ... |  |  |  |
> > | [ | #:timestamp timestamp |  |  |  |
> > |  | #:get-timestamp get-timestamp |  |  |  |
> > |  | #:utc-timestamps? utc-timestamps? |  |  |  |
> > |  | #:round-timestamps-down? round-timestamps-down? |  |  |  |
> > |  | #:path-prefix path-prefix |  |  |  |
> > |  | #:system-type sys-type]) |  | → |  | void?

> zip-file : path-string?
> path : path-string?
> timestamp : (or/c #f exact-integer?) = #f

> | get-timestamp |  | : |  | (path? . -> . exact-integer?)

> =

> (if timestamp
> (lambda (p) timestamp)
> file-or-directory-modify-seconds)

> utc-timestamps? : any/c = #f
> round-timestamps-down? : any/c = #f
> path-prefix : (or/c #f path-string?) = #f
> sys-type : symbol? = (system-type)

Creates zip-file, which holds the complete content of all paths.

The given paths are all expected to be relative path names of existing directories and files (i.e., relative to the current directory). If a nested path is provided as a path, its ancestor directories are also added to the resulting zip file, up to the current directory (using pathlist-closure).

Files are packaged as usual for zip files, including permission bits for both Windows and Unix (including Mac OS). The permission bits are determined by file-or-directory-permissions, which does not preserve the distinction between owner/group/other permissions. Also, symbolic links are always followed.

The get-timestamp function is used to obtain the modification date to record in the archive for a file or directory. Normally, zip archives record modification dates in local time, but if utc-timestamps? is true, then the UTC time is recorded. Timestamps in zip archives are precise only to two seconds; by default, the time is rounded toward the future (like WinZip or PKZIP), but time is rounded toward the past (like Java) if round-timestamps-down? is true.

The sys-type argument determines the system type recorded in the archive.

If path-prefix is not #f, then it prefixes the name of each path as it is written in the zip file, and directory entries are added for each element of path-prefix.

Changed in version 6.0.0.3 of package base: Added the #:get-timestamp and #:system-type arguments.
Changed in version 6.0.1.12: Added the #:path-prefix, #:utc-timestamps?, and #:utc-timestamps-down? arguments.

> > procedure

> > (zip->output |  | paths |
> > | [ | out |
> > |  | #:timestamp timestamp |
> > |  | #:get-timestamp get-timestamp |
> > |  | #:utc-timestamps? utc-timestamps? |
> > |  | #:round-timestamps-down? round-timestamps-down? |
> > |  | #:path-prefix path-prefix |
> > |  | #:system-type sys-type]) |

> → void?
> paths : (listof path-string?)
> out : output-port? = (current-output-port)
> timestamp : (or/c #f exact-integer?) = #f

> | get-timestamp |  | : |  | (path? . -> . exact-integer?)

> =

> (if timestamp
> (lambda (p) timestamp)
> file-or-directory-modify-seconds)

> utc-timestamps? : any/c = #f
> round-timestamps-down? : any/c = #f
> path-prefix : (or/c #f path-string?) = #f
> sys-type : symbol? = (system-type)

Zips each of the given paths, and packages it as a zip “file” that is written directly to out. Unlike zip, the specified paths are included without closing over directories: if a directory is specified, its content is not automatically added, and nested directories are added without parent directories.

Changed in version 6.0.0.3 of package base: Added the #:get-timestamp and #:system-type arguments.
Changed in version 6.0.1.12: Added the #:path-prefix, #:utc-timestamps?, and #:utc-timestamps-down? arguments.

> > parameter

> > (zip-verbose) → boolean?

> (zip-verbose on?) → void?
> on? : any/c

A parameter that controls output during a zip operation. Setting this parameter to a true value causes zip to display to (current-error-port) the filename that is currently being compressed.
top ← prev up next →