Subject: | Archive::Cpio::File size does not return the file size |
When reading a CPIO file that is read using OldBinary, the
Archive::Cpio::File size method does not return the file's size.
I'm guessing that size is supposed to return length($e->{data}) which
does return a size. If not, it would be convenient to add a method to
return the file's size in bytes.
The cpio file was created using the command:
ls perl_installed_modules.pl | cpio -o >test.cpio
A perl script utilizing Archive::Cpio is used to read the cpio file and
output it to STDOUT:
cat test.cpio | ./perl_cpio_out_stdin.pl -v
The required files to run the last command have been attached.
Note: I am aware that GNU cpio has a --to-stdout flag. I wrote this
script to test Archive::Cpio functionality and to be used on older
systems that do not have GNU cpio.
System information:
Perl Version: v5.8.8 built for i486-linux-gnu-thread-multi
OS: 2.6.22-14-generic #1 SMP Sun Oct 14 23:05:12 GMT 2007 i686 GNU/Linux
CPIO Version: cpio (GNU cpio) 2.8
Subject: | test.cpio |
Message body not shown because it is not plain text.
Subject: | perl_cpio_out_stdin.pl |
#!/usr/bin/perl
#
# Script for reading CPIO archives on the fly.
# No files are modified or written.
# Output is sent to STDOUT.
#
# Add the -v flag to force the script to output additional information.
#
# To read an uncompressed CPIO file:
# cat file.cpio | ./perl_cpio_out_stdin.pl
#
# To read a compressed CPIO file:
# uncompress.real -c test.cpio.compressed.Z | ./perl_cpio_out_stdin.pl
#
use Archive::Cpio;
use strict;
my $VERBOSE = 0;
# read in flags
foreach my $arg (@ARGV)
{
if ($arg eq '-h' || $arg eq '-help' || $arg eq '--help' || $arg eq '--h')
{
print "Usage: cat inputfile | $0 [-v] [-h]\n";
print " -v : Print additional information.\n";
print " -h : Print this help message.\n";
exit(0);
}
elsif ($arg eq '-v')
{
$VERBOSE = 1;
}
}
# read cpio file
my $cpio = Archive::Cpio->new;
$cpio->read_with_handler(\*STDIN, sub {
my ($e) = @_;
push @{$cpio->{list}}, $e;
});
# output cpio files to STDOUT
foreach my $cfile ($cpio->get_files())
{
print "Format: " . $cpio->{archive_format} . "\n" if $VERBOSE;
print "File: " . $cfile->name() . "\n" if $VERBOSE;
print "Size: " . $cfile->size() . "\n" if $VERBOSE;
print "Size (length): " . length($cfile->{data}) . "\n" if $VERBOSE;
print $cfile->get_content();
print "__END_OF_FILE__\n" if $VERBOSE;
}