<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">##- Nanar &lt;nanardon@mandriva.org&gt;
##-
##- This program 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, or (at your option)
##- any later version.
##-
##- This program is distributed in the hope that it will be useful,
##- but WITHOUT ANY WARRANTY; without even the implied warranty of
##- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##- GNU General Public License for more details.
##-
##- You should have received a copy of the GNU General Public License
##- along with this program; if not, write to the Free Software
##- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

##- $Id: packdrake.pm,v 1.17 2005/09/06 19:46:17 othauvin Exp $

package packdrake;

use strict;
use warnings;
use Packdrakeng;
our @ISA = qw(Packdrakeng);
our $VERSION = $Packdrakeng::VERSION;

sub new {
    my ($class, $file, %options) = @_;
    my $pack = Packdrakeng-&gt;open(
        %options,
        archive =&gt; $file
    ) or do { print STDERR "Can't open $file: $!\n"; return undef };
    #- rebless
    bless($pack, $class);
}

sub extract_archive {
    my ($pack, $dir, @files) = @_;
    @files or return;
    $pack-&gt;extract($dir, @files);
}

sub extract_all_archive {
    my ($pack, $dir) = @_;
    my ($d, $f, $l) = $pack-&gt;getcontent();
    $pack-&gt;extract($dir, @$d, @$f, @$l);
}

sub list_archive {
    foreach my $archive (@_) {
        my $pack = Packdrakeng-&gt;open(archive =&gt; $archive) or do {
	    print STDERR "Can't open $archive: $!\n";
	    next;
	};
        $pack-&gt;list();
    }
}

sub build_archive {
    my ($listh, $dir, $archive, $size, $compress, $uncompress) = @_;
    my ($comp_level) = $compress =~ m/ -(\d)(?:\s|$)/;
    $compress =~ s/ -\d(\s|$)/$1/;
    my $pack = Packdrakeng-&gt;new(
        archive =&gt; $archive,
        compress =&gt; $compress,
        uncompress =&gt; $uncompress,
        block_size =&gt; $size,
        comp_level =&gt; $comp_level,
    ) or return;
    while (my $line = &lt;$listh&gt;) {
        chomp($line);
        $pack-&gt;add($dir, $line) or return;
    }
    1;
}

sub cat_archive {
    foreach my $archive (@_) {
        my $pack = Packdrakeng-&gt;open(archive =&gt; $archive) or do {
	    print STDERR "Can't open $archive: $!\n";
	    next;
	};
        (undef, my $files, undef) = $pack-&gt;getcontent();
        foreach (@$files) {
            $pack-&gt;extract_virtual(\*STDOUT, $_);
        }
    }
}

1;

__END__

=head1 NAME

packdrake - Simple Archive Extractor/Builder

This module is a compatibility wrapper around the new Packdrakeng module.

=head1 SYNOPSIS

    require packdrake;

    packdrake::cat_archive("/export/media/media_info/hdlist.cz",
                           "/export/media/media_info/hdlist2.cz");
    packdrake::list_archive("/tmp/modules.cz2");

    my $packer = new packdrake("/tmp/modules.cz2");
    $packer-&gt;extract_archive("/tmp", "file1.o", "file2.o");

    my $packer = packdrake::build_archive
        (\*STDIN, "/lib/modules", "/tmp/modules.cz2",
         400000, "bzip2", "bzip2 -d");
    my $packer = packdrake::build_archive
        (\*STDIN, "/export/media/media_info/hdlist.cz",
         400000, "gzip -9", "gzip -d");

=head1 DESCRIPTION

C&lt;packdrake&gt; is a very simple archive extractor and builder used by Mandrakesoft.

=head1 FUNCTIONS

=over

=item B&lt;new($file, %options)&gt;

Open the packdrake archive $file and return a packdrake object.
Return undef on failure.

=item B&lt;&lt; packdrake-&gt;extract_archive($dir, @files) &gt;&gt;

Extract files list into the specified directory.

=item B&lt;&lt; packdrake-&gt;extract_all_archive($dir) &gt;&gt;

Extract all files into the specified directory.

=item B&lt;packdrake::list_archive(@list)&gt;

List files packed into achives given.

=item B&lt;packdrake::build_archive($input,$dir,$archive,$blocksize,$compress,$uncompress)&gt;

Build a new archive:
- $input is a file handle to find file list to pack
- $dir is the directory based where file are located
- $archive is the archive filename to create
- $blocksize is the size of compressed block
- $compress is the program to use to compress data
- $uncompress is the program to use to uncompress data

=item B&lt;packdrake::cat_archive(@files)&gt;

Dump data to STDOUT of files given as parameters, or all files if no files are
specified

=back

=head1 SEE ALSO

L&lt;Packdrakeng&gt;.

=head1 COPYRIGHT

Copyright (C) 2000-2004 Mandrakesoft &lt;nanardon@mandriva.org&gt;

This program 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, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

=cut
</pre></body></html>