6 tar File Creation

▼ |  | 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
| Bibliography
| Index

On this page:

tar
tar->output
tar-gzip

top ← prev up next →

### 6`` tar File Creation

(require file/tar) | package: base

The file/tar library provides utilities to create archive files in USTAR format, like the archive that the Unix utility pax generates. The USTAR format imposes limits on path lengths. The resulting archives contain only directories, files, and symbolic links, and owner information is not preserved; the owner that is stored in the archive is always “root.”
Symbolic links (on Unix and Mac OS X) are not followed by default, and the path in a link must be less than 100 bytes.

> > procedure
> > (tar |  | tar-file |
> > |  | path ... |
> > | [ | #:follow-links? follow-links? |
> > |  | #:exists-ok? exists-ok? |
> > |  | #:path-prefix path-prefix |
> > |  | #:path-filter path-filter |
> > |  | #:get-timestamp get-timestamp]) |
> → exact-nonnegative-integer?
> tar-file : path-string?
> path : path-string?
> follow-links? : any/c = #f
> exists-ok? : any/c = #f
> path-prefix : (or/c #f path-string?) = #f
> path-filter : (or/c #f (path? . -> . any/c)) = #f
> | get-timestamp |  | : |  | (path? . -> . exact-integer?)
> |  |  | = |  |
> (if timestamp
> (lambda (p) timestamp)
> file-or-directory-modify-seconds)

Creates tar-file, which holds the complete content of all paths. The given paths are all expected to be relative paths for 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 tar file, up to the current directory (using pathlist-closure). If follow-links? is false, then symbolic links are included in the resulting tar file as links.

If exists-ok? is #f, then an exception is raised if tar-file exists already. If exists-ok? is true, then tar-file is truncated or replaced if it exists already.

If path-prefix is not #f, then it is prefixed to each path in the archive.

The get-timestamp function is used to obtain the modification date to record in the archive for each file or directory.

Changed in version 6.0.0.3 of package base: Added the #:get-timestamp argument. Changed in version 6.1.1.1: Added the #:exists-ok? argument. Changed in version 6.3.0.3: Added the #:follow-links? argument. Changed in version 6.3.0.11: Added the #:path-filter argument.

> > procedure
> > (tar->output |  | paths |
> > | [ | out |
> > |  | #:follow-links? follow-links? |
> > |  | #:path-prefix path-prefix |
> > |  | #:path-filter path-filter |
> > |  | #:get-timestamp get-timestamp]) |
> → exact-nonnegative-integer?
> paths : (listof path?)
> out : output-port? = (current-output-port)
> follow-links? : any/c = #f
> path-prefix : (or/c #f path-string?) = #f
> path-filter : (or/c #f (path? . -> . any/c)) = #f
> | get-timestamp |  | : |  | (path? . -> . exact-integer?)
> |  |  | = |  |
> (if timestamp
> (lambda (p) timestamp)
> file-or-directory-modify-seconds)

Packages each of the given paths in a tar format archive that is written directly to the out. The specified paths are included as-is (except for adding path-prefix, if any); 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 argument. Changed in version 6.3.0.3: Added the #:follow-links? argument. Changed in version 6.3.0.11: Added the #:path-filter argument.

> > procedure
> > (tar-gzip |  | tar-file |  |  |  |
> > |  | paths ... |  |  |  |
> > | [ | #:follow-links? follow-links? |  |  |  |
> > |  | #:exists-ok? exists-ok? |  |  |  |
> > |  | #:path-prefix path-prefix |  |  |  |
> > |  | #:get-timestamp get-timestamp]) |  | → |  | void?
> tar-file : path-string?
> paths : path-string?
> follow-links? : any/c = #f
> exists-ok? : any/c = #f
> path-prefix : (or/c #f path-string?) = #f
> | get-timestamp |  | : |  | (path? . -> . exact-integer?)
> |  |  | = |  |
> (if timestamp
> (lambda (p) timestamp)
> file-or-directory-modify-seconds)

Like tar, but compresses the resulting file with gzip.

Changed in version 6.0.0.3 of package base: Added the #:get-timestamp argument. Changed in version 6.1.1.1: Added the #:exists-ok? argument. Changed in version 6.3.0.3: Added the #:follow-links? argument.

top ← prev up next →