Annotation of src/usr.bin/compress/compress.1, Revision 1.10
1.10 ! aaron 1: .\" $OpenBSD: compress.1,v 1.9 1999/10/05 17:09:11 aaron Exp $
1.1 deraadt 2: .\" $NetBSD: compress.1,v 1.5 1995/03/26 09:44:34 glass Exp $
3: .\"
4: .\" Copyright (c) 1986, 1990, 1993
5: .\" The Regents of the University of California. All rights reserved.
6: .\"
7: .\" This code is derived from software contributed to Berkeley by
8: .\" James A. Woods, derived from original work by Spencer Thomas
9: .\" and Joseph Orost.
10: .\"
11: .\" Redistribution and use in source and binary forms, with or without
12: .\" modification, are permitted provided that the following conditions
13: .\" are met:
14: .\" 1. Redistributions of source code must retain the above copyright
15: .\" notice, this list of conditions and the following disclaimer.
16: .\" 2. Redistributions in binary form must reproduce the above copyright
17: .\" notice, this list of conditions and the following disclaimer in the
18: .\" documentation and/or other materials provided with the distribution.
19: .\" 3. All advertising materials mentioning features or use of this software
20: .\" must display the following acknowledgement:
21: .\" This product includes software developed by the University of
22: .\" California, Berkeley and its contributors.
23: .\" 4. Neither the name of the University nor the names of its contributors
24: .\" may be used to endorse or promote products derived from this software
25: .\" without specific prior written permission.
26: .\"
27: .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28: .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29: .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30: .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31: .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32: .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33: .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34: .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35: .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36: .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37: .\" SUCH DAMAGE.
38: .\"
39: .\" @(#)compress.1 8.2 (Berkeley) 4/18/94
40: .\"
41: .Dd April 18, 1994
42: .Dt COMPRESS 1
1.7 aaron 43: .Os
1.1 deraadt 44: .Sh NAME
45: .Nm compress ,
46: .Nm uncompress
47: .Nd compress and expand data
48: .Sh SYNOPSIS
49: .Nm compress
1.9 aaron 50: .Op Fl cdftgOqv
1.1 deraadt 51: .Op Fl b Ar bits
1.4 mickey 52: .Op Fl o Ar filename
1.1 deraadt 53: .Op Ar
54: .Nm uncompress
1.4 mickey 55: .Op Fl cftoqv
56: .Op Fl o Ar filename
1.7 aaron 57: .Op Ar
1.1 deraadt 58: .Sh DESCRIPTION
1.9 aaron 59: The
1.8 aaron 60: .Nm
1.9 aaron 61: utility
1.1 deraadt 62: reduces the size of the named files using adaptive Lempel-Ziv coding.
63: Each
64: .Ar file
65: is renamed to the same name plus the extension
66: .Dq .Z .
67: As many of the modification time, access time, file flags, file mode,
68: user ID, and group ID as allowed by permissions are retained in the
69: new file.
70: If compression would not reduce the size of a
71: .Ar file ,
72: the file is ignored.
73: .Pp
1.9 aaron 74: The
1.6 aaron 75: .Nm uncompress
1.9 aaron 76: utility restores compressed files to their original form, renaming the
77: files by removing the
1.1 deraadt 78: .Dq .Z
79: extension.
80: .Pp
81: If renaming the files would cause files to be overwritten and the standard
82: input device is a terminal, the user is prompted (on the standard error
83: output) for confirmation.
84: If prompting is not possible or confirmation is not received, the files
85: are not overwritten.
86: .Pp
87: If no files are specified, the standard input is compressed or uncompressed
88: to the standard output.
1.9 aaron 89: If either the input or output files are not regular files, the checks for
1.1 deraadt 90: reduction in size and file overwriting are not performed, the input file is
91: not removed, and the attributes of the input file are not retained.
92: .Pp
93: The options are as follows:
94: .Bl -tag -width Ds
1.6 aaron 95: .It Fl b Ar bits
1.1 deraadt 96: Specify the
97: .Ar bits
98: code limit (see below).
99: .It Fl c
100: Compressed or uncompressed output is written to the standard output.
101: No files are modified.
1.4 mickey 102: .It Fl d
103: Decompress the source files instead of compressing them.
1.1 deraadt 104: .It Fl f
105: Force compression of
106: .Ar file ,
107: even if it is not actually reduced in size.
108: Additionally, files are overwritten without prompting for confirmation.
1.4 mickey 109: .It Fl g
1.6 aaron 110: Use deflate scheme which reportedly provides better compression rates.
1.4 mickey 111: .It Fl O
112: Use old compression method (default is based on the program name).
1.6 aaron 113: .It Fl o Ar filename
1.4 mickey 114: Set the output file name.
115: .It Fl t
1.6 aaron 116: Test the integrity of each file leaving any files intact.
1.4 mickey 117: .It Fl q
1.6 aaron 118: Be quiet, suppress any messages.
1.1 deraadt 119: .It Fl v
120: Print the percentage reduction of each file.
121: .El
122: .Pp
1.8 aaron 123: .Nm
1.1 deraadt 124: uses a modified Lempel-Ziv algorithm.
125: Common substrings in the file are first replaced by 9-bit codes 257 and up.
126: When code 512 is reached, the algorithm switches to 10-bit codes and
127: continues to use more bits until the
128: limit specified by the
129: .Fl b
1.9 aaron 130: flag is reached.
1.6 aaron 131: .Ar bits
1.9 aaron 132: must be between 9 and 16 (the default is 16).
1.10 ! aaron 133: .\" XXX - use .br here to work-around an apparent bug in mdoc
! 134: .br
1.1 deraadt 135: .Pp
136: After the
137: .Ar bits
138: limit is reached,
1.8 aaron 139: .Nm
1.1 deraadt 140: periodically checks the compression ratio.
141: If it is increasing,
1.8 aaron 142: .Nm
1.1 deraadt 143: continues to use the existing code dictionary.
144: However, if the compression ratio decreases,
1.8 aaron 145: .Nm
1.1 deraadt 146: discards the table of substrings and rebuilds it from scratch. This allows
1.8 aaron 147: the algorithm to adapt to the next
148: .Dq block
149: of the file.
1.1 deraadt 150: .Pp
151: The
152: .Fl b
153: flag is omitted for
1.3 deraadt 154: .Nm uncompress
1.1 deraadt 155: since the
156: .Ar bits
157: parameter specified during compression
158: is encoded within the output, along with
159: a magic number to ensure that neither decompression of random data nor
160: recompression of compressed data is attempted.
161: .Pp
162: .ne 8
163: The amount of compression obtained depends on the size of the
164: input, the number of
165: .Ar bits
166: per code, and the distribution of common substrings.
167: Typically, text such as source code or English is reduced by 50\-60%.
168: Compression is generally much better than that achieved by Huffman
169: coding (as used in the historical command pack), or adaptive Huffman
170: coding (as used in the historical command compact), and takes less
171: time to compute.
172: .Pp
173: The
1.8 aaron 174: .Nm
1.6 aaron 175: utility exits 0 on success, 1 if an error occurred, or 2 if one or
1.5 denny 176: more files were not compressed because they would have grown in
1.6 aaron 177: size (and
178: .Fl f
1.9 aaron 179: was not specified).
1.1 deraadt 180: .Sh SEE ALSO
181: .Rs
182: .%A Welch, Terry A.
183: .%D June, 1984
184: .%T "A Technique for High Performance Data Compression"
185: .%J "IEEE Computer"
186: .%V 17:6
187: .%P pp. 8-19
188: .Re
1.5 denny 189: .Sh STANDARDS
190: The
1.8 aaron 191: .Nm
1.5 denny 192: utility is compliant with the
193: .St -p1003.2-92
194: specification.
1.1 deraadt 195: .Sh HISTORY
196: The
197: .Nm
198: command appeared in
199: .Bx 4.3 .
1.6 aaron 200: The deflate compression support was added in
1.4 mickey 201: .Ox 2.1 .