2 gzip Compression and 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
15 | Globbing
| Bibliography
| Index

On this page:

gzip
gzip-through-ports
deflate

top contents ← prev up next →

### 2`` gzip Compression and File Creation🔗ℹ

(require file/gzip) | package: base

The file/gzip library provides utilities to create archive files in gzip format, or simply to compress data using the pkzip “deflate” method.

> procedure (gzip in-file [out-file]) → void?
> in-file : path-string?
> | out-file |  | : |  | path-string?
> |  |  | = |  | (path-add-extension in-file ".gz" #".")

Compresses data to the same format as the gzip utility, writing the compressed data directly to a file. The in-file argument is the name of the file to compress. If the file named by out-file exists, it will be overwritten.

Changed in version 6.8.0.2 of package base: Changed default expression of out-file to use path-add-extension instead of string-append.

> > procedure
> > (gzip-through-ports |  | in |  |  |  |
> > |  | out |  |  |  |
> > |  | orig-filename |  |  |  |
> > |  | timestamp) |  | → |  | void?
> in : input-port?
> out : output-port?
> orig-filename : (or/c string? #f)
> timestamp : exact-integer?

Reads the port in for data and compresses it to out, outputting the same format as the gzip utility. The orig-filename string is embedded in this output; orig-filename can be #f to omit the filename from the compressed stream. The timestamp number is also embedded in the output stream, as the modification date of the original file (in Unix seconds, as file-or-directory-modify-seconds would report on Unix).

> > procedure
> > (deflate in out) |  | → |  |
> > exact-nonnegative-integer?
> > exact-nonnegative-integer?
> > exact-nonnegative-integer?
> in : input-port?
> out : output-port?

Writes pkzip-format “deflated” data to the port out, compressing data from the port in. The data in a file created by gzip uses this format (preceded with header information).

The result is three values: the number of bytes read from in, the number of bytes written to out, and a cyclic redundancy check (CRC) value for the input.

top contents ← prev up next →