Uncompressing tar.Z files using Compress::Zlib?

B

bmowder

All-

I'm using ActivePerl v5.8.7 built for MSWin32-x86-multi-thread,
Binary build 813 on a windows XP Professional SP2 machine The modules
in use are Archive::Tar V 1.23 and
Compress::Zlib v1.34.

I have been trying to uncompress a tar.Z file so I could open it with
Archive::Tar and extract the contents, but have had no success
whatsoever. I tried Archive::Zip, but it maintains that the files are
NOT .zip files.

I have tried:

for $compressed ( <*.tar.Z> ) {
($outname = $compressed) =~ s/[.]Z$//;
$input="";
$output="";
$istat="";
$ostat="";
$tar= Archive::Tar->new($compressed, 1) or die "Couldn't read file
$compressed\n";
exit(0);
}

Which fails with the message "Can not read compressed format in
tar-mode"

I have tried:

for $compressed ( <*.tar.Z> ) {
($outname = $compressed) =~ s/[.]Z$//;
$input="";
$output="";
$i="";
$istat="";
$ostat="";
($i,$istat)=inflateInit(WindowBits => -Compress::Zlib::MAX_WBITS())
or die "Cannot create a inflation stream\n" ;;
open INFILE, "<$compressed" or die "Couldn't open $compressed to read
$!\n";
open OUTFILE, ">$outname" or die "Couldn't open $outname to write
$!\n";
binmode INFILE;
binmode OUTFILE;
while ( read(INFILE, $inline, 4096) > 0 ) {
$input .= $inline;
}

$input .= " "; #add trailing byte
per Doc.

($output, $status) = $i->inflate(\$input) ;

print OUTFILE $output if $status == Z_OK or $status == Z_STREAM_END ;

close(INFILE);
close(OUTFILE);
die "inflation failed $status\n" unless $status == Z_STREAM_END ;
exit(0);

}

Which fails with the message "inflation failed -3" (-3 translates as
Z_DATA_ERROR)

I have tried:

for $compressed ( <*.tar.Z> ) {
($outname = $compressed) =~ s/[.]Z$//;
$input="";
$output="";
$istat="";
$ostat="";
open INFILE, "<$compressed" or die "Couldn't open $compressed to read
$!\n";
open OUTFILE, ">$outname" or die "Couldn't open $outname to write
$!\n";
binmode INFILE;
binmode OUTFILE;
while ( (read(INFILE, $inline, 4096)) > 0 ) {
$input .= $inline;
}
close(INFILE);

if ( ($output=uncompress($input)) eq undef ) {
die "uncompress failed for $compressed\n";
} else {
print OUTFILE $output;
}
close(OUTFILE);
exit(0);

}

Which fails with the message "uncompress failed for
AT1355_20050930191102.tar.Z"

And a whole lot of other things too tedious to mention, all of which
leaves me wondering,

Has anyone ever succeeded in uncompressing a tar.Z file so that the
..tar file could be accessed in perl, using Compress::Zlib and/or
Archive::Tar on a WIn32 OS?

If anyone has succeeded in doing this, PLEASE tell me how (what
modules, what methods)? Sample code would be most appreciated.

Barney.
 
B

bmowder

usenet (can I call you use? ;-) )-

I HAVE read the documentation. If you see the flaw in what I am
attempting to do, or know a better way to do it, wouldn't it be a whole
bunch more helpful if you would TELL me what it is?

I have been romping all over the documentation, and the approaches I
have used come FROM that documentation. What I was hoping for was
actual help, as opposed to the all-to-common RTFM (which I have done).

If you have actually successfully unpacked a tar.Z file, I would
really like to know how you did it.

Thanks for your time,

Barney
 
U

usenet

I HAVE read the documentation. If you see the flaw in what I am
attempting to do...

Well, lesssee... the documentation says,
Hmmm. And your code tries to.... access compress-utility archives with
Compress::Zlib and Archive::Tar. I'd say there's your flaw right
there. It doesn't matter if you use the "inflate" method or the
"uncompress" method, IT WON'T WORK. You can't "trick" the module into
processing a filetype that it cannot process.
... or know a better way to do it, wouldn't it be a whole
bunch more helpful if you would TELL me what it is?

I don't need to TELL you what it is. The docs give you two functional
alternative approaches which specifically address your situation.
That's why I gave you a link that would take you directly to that code.
I have been romping all over the documentation, and the approaches I
have used come FROM that documentation.

Yeah, but from the wrong part of the docs. That's why I gave you a
link that goes directly to the specific section titled, "Accessing
..tar.Z files" and gives you some code. Try some of THAT code instead.
What I was hoping for was actual help, as opposed to the
all-to-common RTFM (which I have done).

Well, I'm not gonna cut-and-paste the code from the docs. If you
actually have RTFM and tried the code and had problems, we can talk
about that. But, so far, the only problem that I can see that you're
having is reading comprehension.
If you have actually successfully unpacked a tar.Z file, I would
really like to know how you did it.

I did it like the docs said. Worked like a charm. You should try it
sometime.
Thanks for your time,

You are very, very welcome. I'm really looking forward to helping you
again soon.

(where's that ploink button... grrrr, darn Google Groups...)
 
K

Keith Keller

Well, lesssee... the documentation says,

To be fair to the OP, his local documentation (v1.34, I think?) does
not say this. The perldocs for Compress::Zlib must have been updated
after that version was released.

To be fair to David, the OP should have read the link David posted before
complaining. :) The OP should still go read those docs, which suggest
alternatives for reading .Z files.

--keith
 
U

usenet

Keith said:
To be fair to the OP, his local documentation (v1.34, I think?) does
not say this. The perldocs for Compress::Zlib must have been updated
after that version was released.

Ah, this is true (I checked). I would not have responded with such heat
had I realized this (though I would have still chastized the OP for not
checking the link I furnished, which even has the term
"Accessing_.tar.Z_files" embedded in it).

So my apologies to the OP for the amount of heat with which I replied.
My UPDATED advice is to check the UPDATED docs on the module you're
using (the link is the same):
http://search.cpan.org/~pmqs/Compress-Zlib-1.41/Zlib.pm#Accessing_.tar.Z_files

And I'll take the OP out of my killfile. Now where is that
killfile.... grrrr, darn Google Groups...
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top