# -m and -M
push @try, [@args];
+ # Perl's Compress::Raw::Zlib interfaces directly with zlib and
+ # apparently is the only implementation out there which tunes a very
+ # specific parameter of zlib, memLevel, to 9, instead of 8 which is
+ # the default. The module is used, among others, by Compress::Gzip
+ # which in turn is used by IO::Zlib. It was found on the real world on
+ # tarballs generated by Perl 5.10's Module::Build (cf. #618284)
+ push @try, [@args, '--quirk', 'perl'];
+
# apparently, there is an old version of bsd-gzip (or a similar tool
# based on zlib) that creates gz using maximum compression (-9) but
# does not indicate so in the headers. surprisingly, there are many
__attribute__((__format__(__printf__, 1, 2),noreturn));
static void maybe_errx(const char *fmt, ...)
__attribute__((__format__(__printf__, 1, 2),noreturn));
-static void gz_compress(int, int, const char *, uint32_t, int, int, int, int);
+static void gz_compress(int, int, const char *, uint32_t, int, int, int, int, int);
static void usage(void);
static void display_version(void);
static void display_license(void);
const char *progname = argv[0];
int gnu = 0;
int bzold = 0;
+ int quirks = 0;
char *origname = NULL;
uint32_t timestamp = 0;
+ int memlevel = 8; /* zlib's default */
int nflag = 0;
int mflag = 0;
int fflag = 0;
origname = optarg;
break;
case 'k':
+ quirks = 1;
if (strcmp(optarg, "buggy-bsd") == 0) {
/* certain archives made with older versions of
* BSD variants of gzip */
mflag = 1;
/* osflag is NTFS */
osflag = GZIP_OS_NTFS;
+ } else if (strcmp(optarg, "perl") == 0) {
+ /* Perl's Compress::Raw::Zlib */
+ memlevel = 9;
} else {
fprintf(stderr, "%s: unknown quirk!\n", progname);
usage();
timestamp = 0;
if (gnu) {
- if (ntfs_quirk || xflag >= 0) {
+ if (quirks) {
fprintf(stderr, "%s: quirks not supported with --gnu\n", progname);
return 1;
}
gnuzip(STDIN_FILENO, STDOUT_FILENO, origname, timestamp, level, osflag, rsync);
} else if (bzold) {
- if (ntfs_quirk || xflag >= 0) {
+ if (quirks) {
fprintf(stderr, "%s: quirks not supported with --old-bzip\n", progname);
return 1;
}
return 1;
}
- gz_compress(STDIN_FILENO, STDOUT_FILENO, origname, timestamp, level, osflag, xflag, ntfs_quirk);
+ gz_compress(STDIN_FILENO, STDOUT_FILENO, origname, timestamp, level, memlevel, osflag, xflag, ntfs_quirk);
}
return 0;
}
/* compress input to output. */
static void
-gz_compress(int in, int out, const char *origname, uint32_t mtime, int level, int osflag, int xflag, int ntfs_quirk)
+gz_compress(int in, int out, const char *origname, uint32_t mtime, int level, int memlevel, int osflag, int xflag, int ntfs_quirk)
{
z_stream z;
char *outbufp, *inbufp;
z.avail_out = BUFLEN - i;
error = deflateInit2(&z, level, Z_DEFLATED,
- (-MAX_WBITS), 8, Z_DEFAULT_STRATEGY);
+ (-MAX_WBITS), memlevel, Z_DEFAULT_STRATEGY);
if (error != Z_OK)
maybe_err("deflateInit2 failed");
" \ngnu-specific options:\n"
" -R --rsyncable make rsync-friendly archive\n"
" \nzlib-specific options:\n"
- " -k --quirk QUIRK enable a format quirk (buggy-bsd, ntfs)\n");
+ " -k --quirk QUIRK enable a format quirk (buggy-bsd, ntfs, perl)\n");
exit(0);
}