/* deflate.c -- compress data using the deflation algorithm
- Copyright (C) 1999, 2006, 2009-2012 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2006, 2009-2013 Free Software Foundation, Inc.
Copyright (C) 1992-1993 Jean-loup Gailly
This program is free software; you can redistribute it and/or modify
#endif
/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
+#ifndef RSYNC_WIN
+# define RSYNC_WIN 8192
+#endif
+/* Size of rsync window, must be < MAX_DIST */
+
+#define RSYNC_SUM_MATCH(sum) (((sum) & (RSYNC_WIN - 1)) == 0)
+/* Whether window sum matches magic value */
+
/* ===========================================================================
* Local data used by the "longest match" routines.
*/
unsigned good_match;
/* Use a faster search when the previous match is longer than this */
+local ulg rsync_sum; /* rolling sum of rsync window */
+local ulg rsync_chunk_end; /* next rsync sequence point */
/* Values for max_lazy_match, good_match and max_chain_length, depending on
* the desired pack level (0..9). The values given below have been tuned to
#endif
/* prev will be initialized on the fly */
+ /* rsync params */
+ rsync_chunk_end = 0xFFFFFFFFUL;
+ rsync_sum = 0;
+
/* Set the default configuration parameters:
*/
max_lazy_match = configuration_table[pack_level].max_lazy;
strstart = 0;
block_start = 0L;
+ rsync_chunk_end = 0xFFFFFFFFUL;
#ifdef ASMV
match_init(); /* initialize the asm code */
#endif
memcpy((char*)window, (char*)window+WSIZE, (unsigned)WSIZE);
match_start -= WSIZE;
strstart -= WSIZE; /* we now have strstart >= MAX_DIST: */
+ if (rsync_chunk_end != 0xFFFFFFFFUL)
+ rsync_chunk_end -= WSIZE;
block_start -= (long) WSIZE;
}
}
+local void rsync_roll(start, num)
+ unsigned start;
+ unsigned num;
+{
+ unsigned i;
+
+ if (start < RSYNC_WIN) {
+ /* before window fills. */
+ for (i = start; i < RSYNC_WIN; i++) {
+ if (i == start + num) return;
+ rsync_sum += (ulg)window[i];
+ }
+ num -= (RSYNC_WIN - start);
+ start = RSYNC_WIN;
+ }
+
+ /* buffer after window full */
+ for (i = start; i < start+num; i++) {
+ /* New character in */
+ rsync_sum += (ulg)window[i];
+ /* Old character out */
+ rsync_sum -= (ulg)window[i - RSYNC_WIN];
+ if (rsync_chunk_end == 0xFFFFFFFFUL && RSYNC_SUM_MATCH(rsync_sum))
+ rsync_chunk_end = i;
+ }
+}
+
+/* ===========================================================================
+ * Set rsync_chunk_end if window sum matches magic value.
+ */
+#define RSYNC_ROLL(s, n) \
+ do { if (rsync) rsync_roll((s), (n)); } while(0)
+
/* ===========================================================================
* Flush the current block, with given end-of-file flag.
* IN assertion: strstart is set to the end of the current match.
lookahead -= match_length;
- /* Insert new strings in the hash table only if the match length
+ RSYNC_ROLL(strstart, match_length);
+ /* Insert new strings in the hash table only if the match length
* is not too large. This saves time but degrades compression.
*/
if (match_length <= max_insert_length) {
/* No match, output a literal byte */
Tracevv((stderr,"%c",window[strstart]));
flush = ct_tally (0, window[strstart]);
+ RSYNC_ROLL(strstart, 1);
lookahead--;
strstart++;
}
+ if (rsync && strstart > rsync_chunk_end) {
+ ush attr = 0; /* ascii/binary flag */
+
+ flush = 1;
+ /* Reset huffman tree */
+ ct_init(&attr, &method);
+ rsync_chunk_end = 0xFFFFFFFFUL;
+ }
if (flush) FLUSH_BLOCK(0), block_start = strstart;
/* Make sure that we always have enough lookahead, except
*/
lookahead -= prev_length-1;
prev_length -= 2;
+ RSYNC_ROLL(strstart, prev_length+1);
do {
strstart++;
INSERT_STRING(strstart, hash_head);
match_available = 0;
match_length = MIN_MATCH-1;
strstart++;
- if (flush) FLUSH_BLOCK(0), block_start = strstart;
+ if (rsync && strstart > rsync_chunk_end) {
+ ush attr = 0; /* ascii/binary flag */
+
+ /* Reset huffman tree */
+ ct_init(&attr, &method);
+ rsync_chunk_end = 0xFFFFFFFFUL;
+ flush = 1;
+ }
+ if (flush) FLUSH_BLOCK(0), block_start = strstart;
} else if (match_available) {
/* If there was no match at the previous position, output a
* single literal. If there was a match but the current match
* is longer, truncate the previous match to a single literal.
*/
Tracevv((stderr,"%c",window[strstart-1]));
- if (ct_tally (0, window[strstart-1])) {
- FLUSH_BLOCK(0), block_start = strstart;
- }
+ flush = ct_tally (0, window[strstart-1]);
+ if (rsync && strstart > rsync_chunk_end) {
+ ush attr = 0; /* ascii/binary flag */
+
+ /* Reset huffman tree */
+ ct_init(&attr, &method);
+ rsync_chunk_end = 0xFFFFFFFFUL;
+
+ flush = 1;
+ }
+ if (flush) FLUSH_BLOCK(0), block_start = strstart;
+ RSYNC_ROLL(strstart, 1);
strstart++;
lookahead--;
} else {
/* There is no previous match to compare with, wait for
* the next step to decide.
*/
+ if (rsync && strstart > rsync_chunk_end) {
+ ush attr = 0; /* ascii/binary flag */
+
+ /* Reset huffman tree */
+ ct_init(&attr, &method);
+ rsync_chunk_end = 0xFFFFFFFFUL;
+
+ FLUSH_BLOCK(0), block_start = strstart;
+ }
match_available = 1;
+ RSYNC_ROLL(strstart, 1);
strstart++;
lookahead--;
}
(version @value{VERSION}, @value{UPDATED}),
and documents commands for compressing and decompressing data.
- Copyright @copyright{} 1998-1999, 2001-2002, 2006-2007, 2009-2012 Free Software
+ Copyright @copyright{} 1998-1999, 2001-2002, 2006-2007, 2009-2013 Free Software
Foundation, Inc.
Copyright @copyright{} 1992, 1993 Jean-loup Gailly
The @command{gzip} file format is specified in P. Deutsch, @sc{gzip} file
format specification version 4.3,
- @uref{ftp://ftp.isi.edu/in-notes/rfc1952.txt, Internet @abbr{RFC} 1952} (May
+ @uref{http://www.ietf.org/rfc/rfc1952.txt, Internet @abbr{RFC} 1952} (May
1996). The @command{zip} deflation format is specified in P. Deutsch,
@sc{deflate} Compressed Data Format Specification version 1.3,
- @uref{ftp://ftp.isi.edu/in-notes/rfc1951.txt, Internet @abbr{RFC} 1951} (May
+ @uref{http://www.ietf.org/rfc/rfc1951.txt, Internet @abbr{RFC} 1951} (May
1996).
@node Sample
-d, --decompress decompress
-f, --force force overwrite of output file and compress links
-h, --help give this help
+ -k, --keep keep (don't delete) input files
-l, --list list compressed file contents
-L, --license display software license
-n, --no-name do not save or restore the original name and time stamp
-V, --version display version number
-1, --fast compress faster
-9, --best compress better
+ --rsyncable Make rsync-friendly archive
With no FILE, or when FILE is -, read standard input.
@itemx -h
Print an informative help message describing the options then quit.
+ @item --keep
+ @itemx -k
+ Keep (don't delete) input files during compression or decompression.
+
@item --list
@itemx -l
For each compressed file, list the following fields:
into the directory and compress all the files it finds there (or
decompress them in the case of @command{gunzip}).
+@item --rsyncable
+While compressing, synchronize the output occasionally based on the
+input. This can reduce the compression slightly in some cases, but
+means that the @code{rsync} program can take advantage of similarities
+in the uncompressed input when syncronizing two files compressed with
+this flag. @code{gunzip} cannot tell the difference between a
+compressed file created with this option, and one created without it.
+
+@item --rsyncable
+While compressing, synchronize the output occasionally based on
+the input. This increases size by less than 1 percent most
+cases, but means that the @command{rsync} program can much more efficiently
+synchronize files compressed with this flag. @command{gunzip}
+cannot tell the difference between a compressed file created
+with this option, and one created without it.
+
+@item --rsyncable
+While compressing, synchronize the output occasionally based on the
+input. This can reduce the compression slightly in some cases, but
+means that the @code{rsync} program can take advantage of similarities
+in the uncompressed input when syncronizing two files compressed with
+this flag. @code{gunzip} cannot tell the difference between a
+compressed file created with this option, and one created without it.
+
@item --suffix @var{suf}
@itemx -S @var{suf}
Use suffix @var{suf} instead of @samp{.gz}. Any suffix can be
/* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
- Copyright (C) 1999, 2001-2002, 2006-2007, 2009-2012 Free Software
+ Copyright (C) 1999, 2001-2002, 2006-2007, 2009-2013 Free Software
Foundation, Inc.
Copyright (C) 1992-1993 Jean-loup Gailly
#include "ignore-value.h"
#include "stat-time.h"
#include "version.h"
+ #include "yesno.h"
/* configuration */
int to_stdout = 0; /* output to stdout (-c) */
static int decompress = 0; /* decompress (-d) */
static int force = 0; /* don't ask questions, compress links (-f) */
+ static int keep = 0; /* keep (don't delete) input files */
static int no_name = -1; /* don't save or restore the original file name */
static int no_time = -1; /* don't save or restore the original file time */
static int recursive = 0; /* recurse through directories (-r) */
unsigned insize; /* valid bytes in inbuf */
unsigned inptr; /* index of next byte to be processed in inbuf */
unsigned outcnt; /* bytes in output buffer */
+int rsync = 0; /* make ryncable chunks */
static int handled_sig[] =
{
#ifdef SIGHUP
, SIGHUP
#endif
- #ifdef SIGPIPE
+ #if SIGPIPE
, SIGPIPE
#endif
#ifdef SIGTERM
{"force", 0, 0, 'f'}, /* force overwrite of output file */
{"help", 0, 0, 'h'}, /* give help */
/* {"pkzip", 0, 0, 'k'}, force output in pkzip format */
+ {"keep", 0, 0, 'k'}, /* keep (don't delete) input files */
{"list", 0, 0, 'l'}, /* list .gz file contents */
{"license", 0, 0, 'L'}, /* display software license */
{"no-name", 0, 0, 'n'}, /* don't save or restore original name & time */
{"best", 0, 0, '9'}, /* compress better */
{"lzw", 0, 0, 'Z'}, /* make output compatible with old compress */
{"bits", 1, 0, 'b'}, /* max number of bits per code (implies -Z) */
-
+ {"rsyncable", 0, 0, 'R'}, /* make rsync-friendly archive */
{ 0, 0, 0, 0 }
};
" -f, --force force overwrite of output file and compress links",
" -h, --help give this help",
/* -k, --pkzip force output in pkzip format */
+ " -k, --keep keep (don't delete) input files",
" -l, --list list compressed file contents",
" -L, --license display software license",
#ifdef UNDOCUMENTED
" -Z, --lzw produce output compatible with old compress",
" -b, --bits=BITS max number of bits per code (implies -Z)",
#endif
+ " --rsyncable Make rsync-friendly archive",
"",
"With no FILE, or when FILE is -, read standard input.",
"",
z_suffix = Z_SUFFIX;
z_len = strlen(z_suffix);
- while ((optc = getopt_long (argc, argv, "ab:cdfhH?lLmMnNqrS:tvVZ123456789",
+ while ((optc = getopt_long (argc, argv, "ab:cdfhH?klLmMnNqrS:tvVZ123456789",
longopts, (int *)0)) != -1) {
switch (optc) {
case 'a':
force++; break;
case 'h': case 'H':
help(); do_exit(OK); break;
+ case 'k':
+ keep = 1; break;
case 'l':
list = decompress = to_stdout = 1; break;
case 'L':
#else
recursive = 1;
#endif
- break;
- case 'S':
+ break;
+ case 'R':
+ rsync = 1; break;
+
+ case 'S':
#ifdef NO_MULTIPLE_DOTS
if (*optarg == '.') optarg++;
#endif
ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
#endif
+#ifdef SIGPIPE
exiting_signal = quiet ? SIGPIPE : 0;
+#else
+ exiting_signal = 0;
+#endif
install_signal_handlers ();
/* And get to work */
if (!to_stdout)
{
- sigset_t oldset;
- int unlink_errno;
copy_stat (&istat);
if (close (ofd) != 0)
write_error ();
- sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
- remove_ofname_fd = -1;
- unlink_errno = xunlink (ifname) == 0 ? 0 : errno;
- sigprocmask (SIG_SETMASK, &oldset, NULL);
-
- if (unlink_errno)
+ if (!keep)
{
- WARN ((stderr, "%s: ", program_name));
- if (!quiet)
+ sigset_t oldset;
+ int unlink_errno;
+
+ sigprocmask (SIG_BLOCK, &caught_signals, &oldset);
+ remove_ofname_fd = -1;
+ unlink_errno = xunlink (ifname) == 0 ? 0 : errno;
+ sigprocmask (SIG_SETMASK, &oldset, NULL);
+
+ if (unlink_errno)
{
- errno = unlink_errno;
- perror (ifname);
+ WARN ((stderr, "%s: ", program_name));
+ if (!quiet)
+ {
+ errno = unlink_errno;
+ perror (ifname);
+ }
}
}
}
/* gzip.h -- common declarations for all gzip modules
- Copyright (C) 1997-1999, 2001, 2006-2007, 2009-2012 Free Software
+ Copyright (C) 1997-1999, 2001, 2006-2007, 2009-2013 Free Software
Foundation, Inc.
Copyright (C) 1992-1993 Jean-loup Gailly.
extern unsigned insize; /* valid bytes in inbuf */
extern unsigned inptr; /* index of next byte to be processed in inbuf */
extern unsigned outcnt; /* bytes in output buffer */
+extern int rsync; /* deflate into rsyncable chunks */
extern off_t bytes_in; /* number of input bytes */
extern off_t bytes_out; /* number of output bytes */
/* in inflate.c */
extern int inflate (void);
-
- /* in yesno.c */
- extern int yesno (void);
[ diff_options ] file1
[ file2 ]
.SH DESCRIPTION
+.P
.I Zcmp
and
.I zdiff
.I cmp
or
.IR diff "."
- If only one file is specified, then it is compared to a file with the same name
- without the
- .I ".gz"
- extension. If two files are specified, then they are uncompressed if necessary
- and fed to
+ If only
+ .I file1
+ is specified, it is compared to the uncompressed contents of
+ .IR file1 ".gz."
+ If two files are specified, their contents (uncompressed if necessary) are fed to
.I cmp
or
.IR diff "."
+ The input files are not modified.
The exit status from
.I cmp
or
.I cmp
or
.I diff
- programs refer to temporary filenames instead of those specified.
+ programs may refer to file names such as "\-" instead of to the file
+ names specified.