NetBSD/usr.bin/compress/compress.1

174 lines
5.3 KiB
Groff
Raw Normal View History

.\" $NetBSD: compress.1,v 1.14 2003/08/07 11:13:28 agc Exp $
.\"
1994-06-13 18:48:14 +04:00
.\" Copyright (c) 1986, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
1993-03-21 12:45:37 +03:00
.\"
.\" This code is derived from software contributed to Berkeley by
.\" James A. Woods, derived from original work by Spencer Thomas
.\" and Joseph Orost.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
1993-03-21 12:45:37 +03:00
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)compress.1 8.2 (Berkeley) 4/18/94
1993-03-21 12:45:37 +03:00
.\"
.Dd January 23, 2003
1993-03-21 12:45:37 +03:00
.Dt COMPRESS 1
.Os
1993-03-21 12:45:37 +03:00
.Sh NAME
.Nm compress ,
.\".Nm uncompress ,
.Nm uncompress
.\".Nm zcat
1993-03-21 12:45:37 +03:00
.Nd compress and expand data
.Sh SYNOPSIS
.Nm
2003-01-23 11:51:00 +03:00
.Op Fl cdfv
1993-03-21 12:45:37 +03:00
.Op Fl b Ar bits
.Op Ar
.Nm uncompress
2003-01-23 11:51:00 +03:00
.Op Fl cdfv
2001-12-01 19:43:07 +03:00
.Op Ar
.\".Nm zcat
.\".Op Ar
1993-03-21 12:45:37 +03:00
.Sh DESCRIPTION
.Nm
1993-03-21 12:45:37 +03:00
reduces the size of the named files using adaptive Lempel-Ziv coding.
1994-06-13 18:48:14 +04:00
Each
1993-03-21 12:45:37 +03:00
.Ar file
1994-06-13 18:48:14 +04:00
is renamed to the same name plus the extension
.Dq .Z .
As many of the modification time, access time, file flags, file mode,
user ID, and group ID as allowed by permissions are retained in the
new file.
If compression would not reduce the size of a
1993-03-21 12:45:37 +03:00
.Ar file ,
1994-06-13 18:48:14 +04:00
the file is ignored.
.Pp
.Nm uncompress
1994-06-13 18:48:14 +04:00
restores the compressed files to their original form, renaming the
files by deleting the
.Dq .Z
extension.
.\".Pp
.\".Nm Zcat
.\"is an alias for
.\".Dq "uncompress -c" .
1994-06-13 18:48:14 +04:00
.Pp
If renaming the files would cause files to be overwritten and the standard
input device is a terminal, the user is prompted (on the standard error
output) for confirmation.
If prompting is not possible or confirmation is not received, the files
are not overwritten.
.Pp
If no files are specified, the standard input is compressed or uncompressed
to the standard output.
If either the input and output files are not regular files, the checks for
reduction in size and file overwriting are not performed, the input file is
not removed, and the attributes of the input file are not retained.
.Pp
The options are as follows:
.Bl -tag -width Ds
1993-03-21 12:45:37 +03:00
.It Fl b
1994-06-13 18:48:14 +04:00
Specify the
1993-03-21 12:45:37 +03:00
.Ar bits
code limit (see below).
1994-06-13 18:48:14 +04:00
.It Fl c
Compressed or uncompressed output is written to the standard output.
No files are modified.
.It Fl d
Force decompression.
1994-06-13 18:48:14 +04:00
.It Fl f
Force compression of
.Ar file ,
even if it is not actually reduced in size.
Additionally, files are overwritten without prompting for confirmation.
1993-03-21 12:45:37 +03:00
.It Fl v
Print the percentage reduction of each file.
.El
.Pp
.Nm
1994-06-13 18:48:14 +04:00
uses a modified Lempel-Ziv algorithm.
1993-03-21 12:45:37 +03:00
Common substrings in the file are first replaced by 9-bit codes 257 and up.
When code 512 is reached, the algorithm switches to 10-bit codes and
continues to use more bits until the
limit specified by the
.Fl b
1994-06-13 18:48:14 +04:00
flag is reached (the default is 16).
1993-03-21 12:45:37 +03:00
.Ar Bits
1994-06-13 18:48:14 +04:00
must be between 9 and 16.
1993-03-21 12:45:37 +03:00
.Pp
After the
.Ar bits
1994-06-13 18:48:14 +04:00
limit is reached,
.Nm
1994-06-13 18:48:14 +04:00
periodically checks the compression ratio.
If it is increasing,
.Nm
1994-06-13 18:48:14 +04:00
continues to use the existing code dictionary.
However, if the compression ratio decreases,
.Nm
1993-03-21 12:45:37 +03:00
discards the table of substrings and rebuilds it from scratch. This allows
the algorithm to adapt to the next "block" of the file.
.Pp
1994-06-13 18:48:14 +04:00
The
1993-03-21 12:45:37 +03:00
.Fl b
flag is omitted for
.Ar uncompress
since the
.Ar bits
parameter specified during compression
is encoded within the output, along with
a magic number to ensure that neither decompression of random data nor
recompression of compressed data is attempted.
.Pp
The amount of compression obtained depends on the size of the
input, the number of
.Ar bits
per code, and the distribution of common substrings.
1994-06-13 18:48:14 +04:00
Typically, text such as source code or English is reduced by 50\-60%.
Compression is generally much better than that achieved by Huffman
coding (as used in the historical command pack), or adaptive Huffman
coding (as used in the historical command compact), and takes less
time to compute.
1993-03-21 12:45:37 +03:00
.Pp
1994-06-13 18:48:14 +04:00
The
.Nm
utility exits 0 on success, and \*[Gt]0 if an error occurs.
1994-06-13 18:48:14 +04:00
.Sh SEE ALSO
.Xr zcat 1
1994-06-13 18:48:14 +04:00
.Rs
.%A Welch, Terry A.
.%D June, 1984
.%T "A Technique for High Performance Data Compression"
.%J "IEEE Computer"
.%V 17:6
.%P pp. 8-19
.Re
1993-03-21 12:45:37 +03:00
.Sh HISTORY
The
.Nm
command appeared in
.Bx 4.3 .