View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Alexey Tourbin > RPM-Payload-0.11 > RPM::Payload



Annotate this POD

View/Report Bugs
Module Version: 0.11   Source  


RPM::Payload - simple in-memory access to RPM cpio archive


    use RPM::Payload;
    my $cpio = RPM::Payload->new("rpm-3.0.4-0.48.i386.rpm");
    while (my $entry = $cpio->next) {
        print $entry->filename, "\n";


RPM::Payload provides in-memory access to RPM cpio archive. Cpio headers and file data can be read in a simple loop. RPM::Payload uses rpm2cpio program which comes with RPM.


Piece of Bourne shell code:

        tmpdir=`mktemp -dt rpmfile.XXXXXXXX`
        rpm2cpio "$1" |(cd "$tmpdir"
            cpio -idmu --quiet --no-absolute-filenames
            chmod -Rf u+rwX .
            find -type f -print0 |xargs -r0 file)
        rm -rf "$tmpdir"

Sample output:

    $ rpmfile rss2mail2-2.25-alt1.noarch.rpm 
    ./usr/share/man/man1/rss2mail2.1.gz: gzip compressed data, from Unix, max compression
    ./usr/bin/rss2mail2:                 perl script text executable
    ./etc/rss2mail2rc:                   ASCII text

Perl implementation:

    use RPM::Payload;
    use Fcntl qw(S_ISREG);
    use File::LibMagic qw(MagicBuffer);
    sub rpmfile {
        my $f = shift;
        my $cpio = RPM::Payload->new($f);
        while (my $entry = $cpio->next) {
            next unless S_ISREG($entry->mode);
            next unless $entry->size > 0;
            $entry->read(my $buf, 8192) > 0 or die "read error";
            print $entry->filename, "\t", MagicBuffer($buf), "\n";


rpm2cpio program (which comes with RPM) must be installed.

It will die on error, so you may need an enclosing eval block. However, they say "when you must fail, fail noisily and as soon as possible".

Entries obtained with $cpio->next are coupled with current position in $cpio stream. Thus, $entry->read and $entry->readlink methods may only be invoked before the next $cpio->next call.

Hradlinks must be handled manually. Alternatively, you may want to skip entries with $entry->size == 0 altogether.


Written by Alexey Tourbin <>.


Copyright (c) 2006, 2009 Alexey Tourbin, ALT Linux Team.

This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.



Edward C. Bailey. Maximum RPM. (RPM File Format).

Eric S. Raymond. The Art of Unix Programming. (Rule of Repair).

syntax highlighting: