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