Archive::Tar, difference in size of output file

J

Justin C

I'm working on a program to create .tgz archives of catalogue images for
our customers to download. Initially I was doing this:

my $tar = Archive::Tar->new();
foreach my $dir (0..9, 'a'..'z') {
$tar->add_files(glob "$dir/*jpg");
}
$tar->write($fname, COMPRESS_GZIP, "catalogue_images")

This was creating .tgz files much, much larger than the total
uncompressed size of images. I decided to try a different way of
creating the archive, and now do this:

my @files;
foreach my $dir (0..9, 'a'..'z') {
push @files, glob "$dir/*jpg";
}
Archive::Tar->create_archive($fname, COMPRESS_GZIP, @files);

and the file sizes are, as I would expect, much smaller.

Can someone tell me why this is?

Justin.
 
P

Peter Makholm

Justin C said:
my $tar = Archive::Tar->new();
foreach my $dir (0..9, 'a'..'z') {
$tar->add_files(glob "$dir/*jpg");
}
$tar->write($fname, COMPRESS_GZIP, "catalogue_images")

This was creating .tgz files much, much larger than the total
uncompressed size of images.

If you examine the resulting file, does it contain exactly what you
expect?
I decided to try a different way of creating the archive, and now do
this:

my @files;
foreach my $dir (0..9, 'a'..'z') {
push @files, glob "$dir/*jpg";
}
Archive::Tar->create_archive($fname, COMPRESS_GZIP, @files);

When I lookup the implementation of create_archive, it looks exactly
like this:

sub create_archive {
my $class = shift;

my $file = shift; return unless defined $file;
my $gzip = shift || 0;
my @files = @_;

unless( @files ) {
return $class->_error( qq[Cowardly refusing to create empty
archive!] );
}

my $tar = $class->new;
$tar->add_files( @files );
return $tar->write( $file, $gzip );
}

That is almost the same as you initial version, except for the use of
a prefix.

//Makholm
 
J

Justin C

If you examine the resulting file, does it contain exactly what you
expect?

Yes. But I'm not able to recreate this problem now. I've tried changing
the code back but I must have missed something because the files are now
the almost identical sizes (+/-200 bytes in the case of one, and +/-2000 in
the case of another).

Thank you for your help, but it looks like there could have been
something else in my code causing this, but I left it out when trying to
re-create it.

Justin.
 
J

Justin C

I don't see that here: the two files are exactly the same size. What
version of Archive::Tar are you using? Can you see what the difference
is between the two files: is one of them simply not compressed?

Thank you for your reply, Ben. I've had another look at this and now I'm
not able to recreate it. It wasn't a one of, it was consistenly
happening until I changed my code. Though the contents of a tgz created
using each method contained identical files, the .tgz files were
dramatically different (about four times the size - and bigger than the
uncompressed directory tree!).

I shall, should I post a similar query another time, ensure to not
detroy my code before the fault with it can be found (as I'm sure now
that the fault is with me and not Archive::Tar because I can't recreate
this).

Sorry for wasting your time on this.

Justin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top