Why did Perl Archive :: Tar run out of memory?

I am using the Perl code below to list files in a tar archive. The tar archive is always about 15 MB in size.

my $file = shift;
my $tar = Archive::Tar->new("$file");
my @lists = $tar->list_files;
$tar->error unless @lists;

Executing this code gives me an "Out of Memory" error. I have about 512 MB on my Linux system and I do not want to increase the memory of my system. Can someone please suggest me if this code can be modified to improve performance or other code to display files in a tar archive.

+5
source share
3 answers

I tried this on a big tar and got an error. Probably a bug in libs. The following worked for me:

@files = split/\n/, `tar tf $file`
+3
source

From the FAQ :Archive::Tar

:: ? . perl, , /bin/tar. . , /bin/tar .

:: , /bin/tar? , . . Compress:: Zlib IO:: Zlib , , . , .

, extract_archive. .

iter tarball .

 

, , (untested):

my $next = Archive::Tar->iter( $file );

while ( my $f = $next->() ) {
    say $f->name;
}

/I3az/

+6

Perl , tar

$ tar tvf file.tar
0

All Articles