Annotation of src/usr.bin/compress/compress.1, Revision 1.8
1.8 ! aaron 1: .\" $OpenBSD: compress.1,v 1.7 1999/06/05 01:21:22 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.4 mickey 50: .Op Fl cftgOqv
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.8 ! aaron 59: .Nm
1.1 deraadt 60: reduces the size of the named files using adaptive Lempel-Ziv coding.
61: Each
62: .Ar file
63: is renamed to the same name plus the extension
64: .Dq .Z .
65: As many of the modification time, access time, file flags, file mode,
66: user ID, and group ID as allowed by permissions are retained in the
67: new file.
68: If compression would not reduce the size of a
69: .Ar file ,
70: the file is ignored.
71: .Pp
1.6 aaron 72: .Nm uncompress
1.1 deraadt 73: restores the compressed files to their original form, renaming the
74: files by deleting the
75: .Dq .Z
76: extension.
77: .Pp
78: If renaming the files would cause files to be overwritten and the standard
79: input device is a terminal, the user is prompted (on the standard error
80: output) for confirmation.
81: If prompting is not possible or confirmation is not received, the files
82: are not overwritten.
83: .Pp
84: If no files are specified, the standard input is compressed or uncompressed
85: to the standard output.
86: If either the input and output files are not regular files, the checks for
87: reduction in size and file overwriting are not performed, the input file is
88: not removed, and the attributes of the input file are not retained.
89: .Pp
90: The options are as follows:
91: .Bl -tag -width Ds
1.6 aaron 92: .It Fl b Ar bits
1.1 deraadt 93: Specify the
94: .Ar bits
95: code limit (see below).
96: .It Fl c
97: Compressed or uncompressed output is written to the standard output.
98: No files are modified.
1.4 mickey 99: .It Fl d
100: Decompress the source files instead of compressing them.
1.1 deraadt 101: .It Fl f
102: Force compression of
103: .Ar file ,
104: even if it is not actually reduced in size.
105: Additionally, files are overwritten without prompting for confirmation.
1.4 mickey 106: .It Fl g
1.6 aaron 107: Use deflate scheme which reportedly provides better compression rates.
1.4 mickey 108: .It Fl O
109: Use old compression method (default is based on the program name).
1.6 aaron 110: .It Fl o Ar filename
1.4 mickey 111: Set the output file name.
112: .It Fl t
1.6 aaron 113: Test the integrity of each file leaving any files intact.
1.4 mickey 114: .It Fl q
1.6 aaron 115: Be quiet, suppress any messages.
1.1 deraadt 116: .It Fl v
117: Print the percentage reduction of each file.
118: .El
119: .Pp
1.8 ! aaron 120: .Nm
1.1 deraadt 121: uses a modified Lempel-Ziv algorithm.
122: Common substrings in the file are first replaced by 9-bit codes 257 and up.
123: When code 512 is reached, the algorithm switches to 10-bit codes and
124: continues to use more bits until the
125: limit specified by the
126: .Fl b
127: flag is reached (the default is 16).
1.6 aaron 128: .Ar bits
1.1 deraadt 129: must be between 9 and 16.
130: .Pp
131: After the
132: .Ar bits
133: limit is reached,
1.8 ! aaron 134: .Nm
1.1 deraadt 135: periodically checks the compression ratio.
136: If it is increasing,
1.8 ! aaron 137: .Nm
1.1 deraadt 138: continues to use the existing code dictionary.
139: However, if the compression ratio decreases,
1.8 ! aaron 140: .Nm
1.1 deraadt 141: discards the table of substrings and rebuilds it from scratch. This allows
1.8 ! aaron 142: the algorithm to adapt to the next
! 143: .Dq block
! 144: of the file.
1.1 deraadt 145: .Pp
146: The
147: .Fl b
148: flag is omitted for
1.3 deraadt 149: .Nm uncompress
1.1 deraadt 150: since the
151: .Ar bits
152: parameter specified during compression
153: is encoded within the output, along with
154: a magic number to ensure that neither decompression of random data nor
155: recompression of compressed data is attempted.
156: .Pp
157: .ne 8
158: The amount of compression obtained depends on the size of the
159: input, the number of
160: .Ar bits
161: per code, and the distribution of common substrings.
162: Typically, text such as source code or English is reduced by 50\-60%.
163: Compression is generally much better than that achieved by Huffman
164: coding (as used in the historical command pack), or adaptive Huffman
165: coding (as used in the historical command compact), and takes less
166: time to compute.
167: .Pp
168: The
1.8 ! aaron 169: .Nm
1.6 aaron 170: utility exits 0 on success, 1 if an error occurred, or 2 if one or
1.5 denny 171: more files were not compressed because they would have grown in
1.6 aaron 172: size (and
173: .Fl f
174: was not specifed).
1.1 deraadt 175: .Sh SEE ALSO
176: .Rs
177: .%A Welch, Terry A.
178: .%D June, 1984
179: .%T "A Technique for High Performance Data Compression"
180: .%J "IEEE Computer"
181: .%V 17:6
182: .%P pp. 8-19
183: .Re
1.5 denny 184: .Sh STANDARDS
185: The
1.8 ! aaron 186: .Nm
1.5 denny 187: utility is compliant with the
188: .St -p1003.2-92
189: specification.
1.1 deraadt 190: .Sh HISTORY
191: The
192: .Nm
193: command appeared in
194: .Bx 4.3 .
1.6 aaron 195: The deflate compression support was added in
1.4 mickey 196: .Ox 2.1 .