muba has asked for the wisdom of the Perl Monks concerning the following question:

Heya,

I'm trying to write a simple program which adds, updates, removes or shows files from a .tar.gz file. For this purpose, I am of course using the Tar::Archive module. Then, when I try to add a file, checksum errors appear on the screen. The file size of the .tar.gz increases but the file is not there. I am using ActivePerl 5.6.1 on Windows XP Professional.

Part of the code:
use strict; use Archive::Tar; my $tar = Archive::Tar->new; #read "package.tar.gz" as a compressed file $tar->read("package.tar.gz", 1); #... $file = "addfile.txt"; #not using die here to prevent the "at pack.pl line x" part open THEFILE, "<$file" or do{print "Could not open $file: $!\n"; exit 1}; #get file contents $data = {local $/ = undef; <THEFILE>}; close THEFILE or do{print "Could not close $file: $!\n"; exit 1}; #create a file in the archive named after the original file, store +d in directory pagepack. #copy the contents of the file to the archived file $tar->add_files("pagepack/$file"); $tar->add_dat("pagepack/$file", $data); #save the file as a compressed archive #This is where the checksum errors seem to appear $tar->write("package.tar.gz", 1);


Whenever I try to access the archive again after this operation, I get the checksum errors again. What's wrong? Is this a bug? Do I do something wrong? I don't get it anymore...

my $native_language = "Dutch";
my $code = not $tested unless $specified{$otherwise};

Replies are listed 'Best First'.
Re: checksum error in Archive::Tar
by tachyon (Chancellor) on Mar 15, 2004 at 20:44 UTC

    Win32 == binmode your binary file handles, perl does on the fly conversion between \r\n CRLF and \n on Win32 which is probably the issue. You may have to binmode STDIN and STDOUT as well.

    binmode THEFILE; # :-)

    BTW you have heard of die it will print an error message for you and exit with a true value like for example 1 so do{print "Could not close $file: $!\n"; exit 1}; is what most people would write as just die "Blah $!\n"

    cheers

    tachyon

      Could that be the problem? Since I do not open binary files myself: the Archive::Tar module handles reading and saving the archive files... but maybe binmode is the corner I should look... I'll examine the module.
      I did not use 'die' to prevent the 'at d:\exec\perl\cn\pack.pl line 47' (or whatsoever) message
      
      my $native_language = "Dutch";
      my $code = not $tested unless $specified{$otherwise};
      
Re: checksum error in Archive::Tar
by Taulmarill (Deacon) on Mar 15, 2004 at 16:07 UTC
    did you make shure you have IO::Zlib working corectly?
    does this error occure only with this file or are no files accessable? Maybe the file is broken.
    oh yes, and whoud you c&p you error message to us, so we can see it directly, this helps sometimes.