Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Archive::Tar::Streamed Unexpected end-of-file

by DanEllison (Sexton)
on Jan 06, 2011 at 20:55 UTC ( #880940=perlquestion: print w/ replies, xml ) Need Help??
DanEllison has asked for the wisdom of the Perl Monks concerning the following question:

I need to tar up a group of data files. I've been trying to write my apps to be portable between windows and UNIX, so I was using Archive::Tar::Streamed as opposed to calling tar through a system call.

It all seems to be working fine, however, when I test my tar file by listing or extracting the contents, althought the contents all seem to be good, I'm getting an "Unexpected end-of-file" error on UNIX

Am I not updating or closing the tar file properly?

This is not my exact code, but a snipet that produces the same result:

#! /bin/perl use Archive::Tar::Streamed; my $fh; open $fh, ">test.tar"; binmode $fh; my $tar = Archive::Tar::Streamed->new($fh) or die "Could not open tar +file"; $tar->add(@ARGV); $fh->close;

When I run it I get:

delli28@apsa9012:/u/delli28> test.pl test.pl delli28@apsa9012:/u/delli28> tar tf test.tar test.pl tar: Unexpected end-of-file while reading from the storage media.

Or maybe someone has an entirely better solution, but I will be working with very large files...

Comment on Archive::Tar::Streamed Unexpected end-of-file
Select or Download Code
Re: Archive::Tar::Streamed Unexpected end-of-file
by Anonymous Monk on Jan 07, 2011 at 00:44 UTC
    When reporting problems with modules, report version numbers, use Devel::Modlist like
    $ perl -d:Modlist -e "use CGI;" CGI 3.51 CGI::Util 3.51 Carp 1.11 Exporter 5.63 constant 1.19 overload 1.07 vars 1.01 warnings 1.06 warnings::register 1.01
    Now, looking at the source of Archive::Tar::Streamed, there is literally nothing to it, its barely 45 lines, and it hasn't been updated since 2005, while Archive::Tar has on 18 Dec 2010.

    I would ask the Archive::Tar maintainer to review Archive::Tar::Streamed, he should be able to tell instantly if syswrite $self->{file}, $tf, length($tf) - (BLOCK * 2);
    makes sense :)

Re: Archive::Tar::Streamed Unexpected end-of-file
by ahmad (Hermit) on Jan 07, 2011 at 02:31 UTC

    Actually, You're not closing the file handle correctly.

    Your $fh has no ->close method, it should be written as close $fh; instead;

    As for the end of file, try running this before closing the file $tar->writeeof;

      Your $fh has no ->close method, it should be written as close $fh; instead;

      Um, yes it does :) otherwise it would die with an error

      $ perl -e" STDOUT->close" Can't locate object method "close" via package "IO::Handle" at -e line + 1. $ perl -MIO::File -e" STDOUT->close"
      BTY, thanks. The $tar->writeeof was the ticket.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://880940]
Approved by planetscape
Front-paged by planetscape
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2014-04-20 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls