Annotation of src/usr.bin/compress/compress.1, Revision 1.9
1.9 ! aaron 1: .\" $OpenBSD: compress.1,v 1.8 1999/07/04 11:53:52 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.1 deraadt 133: .Pp
134: After the
135: .Ar bits
136: limit is reached,
1.8 aaron 137: .Nm
1.1 deraadt 138: periodically checks the compression ratio.
139: If it is increasing,
1.8 aaron 140: .Nm
1.1 deraadt 141: continues to use the existing code dictionary.
142: However, if the compression ratio decreases,
1.8 aaron 143: .Nm
1.1 deraadt 144: discards the table of substrings and rebuilds it from scratch. This allows
1.8 aaron 145: the algorithm to adapt to the next
146: .Dq block
147: of the file.
1.1 deraadt 148: .Pp
149: The
150: .Fl b
151: flag is omitted for
1.3 deraadt 152: .Nm uncompress
1.1 deraadt 153: since the
154: .Ar bits
155: parameter specified during compression
156: is encoded within the output, along with
157: a magic number to ensure that neither decompression of random data nor
158: recompression of compressed data is attempted.
159: .Pp
160: .ne 8
161: The amount of compression obtained depends on the size of the
162: input, the number of
163: .Ar bits
164: per code, and the distribution of common substrings.
165: Typically, text such as source code or English is reduced by 50\-60%.
166: Compression is generally much better than that achieved by Huffman
167: coding (as used in the historical command pack), or adaptive Huffman
168: coding (as used in the historical command compact), and takes less
169: time to compute.
170: .Pp
171: The
1.8 aaron 172: .Nm
1.6 aaron 173: utility exits 0 on success, 1 if an error occurred, or 2 if one or
1.5 denny 174: more files were not compressed because they would have grown in
1.6 aaron 175: size (and
176: .Fl f
1.9 ! aaron 177: was not specified).
1.1 deraadt 178: .Sh SEE ALSO
179: .Rs
180: .%A Welch, Terry A.
181: .%D June, 1984
182: .%T "A Technique for High Performance Data Compression"
183: .%J "IEEE Computer"
184: .%V 17:6
185: .%P pp. 8-19
186: .Re
1.5 denny 187: .Sh STANDARDS
188: The
1.8 aaron 189: .Nm
1.5 denny 190: utility is compliant with the
191: .St -p1003.2-92
192: specification.
1.1 deraadt 193: .Sh HISTORY
194: The
195: .Nm
196: command appeared in
197: .Bx 4.3 .
1.6 aaron 198: The deflate compression support was added in
1.4 mickey 199: .Ox 2.1 .