Diff-debs: what options are used for gzip compression in .deb files?

Anderson Lizardo andersonlizardo at yahoo.com.br
Sat Jan 14 18:12:34 GMT 2006


John C. McCabe-Dansted wrote:
> However, I cannot figure out which gzip&options ubuntu uses to create 
> data.tar.gz (in this case from kamera_4%3a3.5.0-0ubuntu0breezy1.2_i386.deb, 
> extracted using ark).
> 
> wc -c data.tar.gz 
>     && gunzip < data.tar.gz | gzip | wc -c 
>     && gunzip < data.tar.gz | gzip -9  | wc -c
> 
> gives me:
> 
> 85795 data.1.2.tar.gz
> 85054
> 84706
> 
> So it seems ubuntu doesn't use /usr/bin/gzip to generate data.tar.gz, with 
> either default compression or --best compression.  Why not? It seems like 
> --best would save space (1k in this case) if nothing else.
> 

Sometime ago I was working on a simple script that creates a
"pseudo-xdelta" (actually a tar file containing the xdeltas of
control.tar.gz, data.tar.gz and debian-binary), and I've noticed this
too. It comes out that (if I understood the dpkg code correctly)
dpkg-deb uses zlib internally to write the .gz files using a fixed block
size of 4096 bytes, which AFAIK is different from gzip's default.
Unfortunately, gzip doesn't come with an option to modify the block size.

I wrote the following simple script that "fixes" a data.tar.gz or
control.tar.gz file compressed by gzip to match that generated by
dpkg-deb (basically it's equivalent to what dpkg does in C):

#!/usr/bin/perl
# (C) 2006 Anderson Lizardo
# "Fix" gzip files to match dpkg-deb's output.
# Usage: fix_gz.pl data.tar.gz > data_fixed.tar.gz

use strict;
use warnings;

use Compress::Zlib;

die "Usage: $0 <file.gz>\n" if @ARGV ne 1;

my $buffer;
my $orig_file = shift;

my $gz1 = gzopen("$orig_file", "r");
die "Could not open $orig_file: $!\n" unless $gz1;
my $gz2 = gzopen(\*STDOUT, "w9");

while ($gz1->gzread($buffer, 4096) > 0) {
        $gz2->gzwrite($buffer);
}
$gz2->gzclose;
$gz1->gzclose;

-- 
Anderson Lizardo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://lists.ubuntu.com/archives/ubuntu-devel/attachments/20060114/73714e82/signature.pgp


More information about the ubuntu-devel mailing list