aboutsummaryrefslogtreecommitdiffstats
path: root/packdrake.pm
blob: b8a77d75a3d1c8d77a450fe1343c01c334ba58e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
##- Nanar <nanardon@mandrake.org>
##-
##- 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$

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->open(
        %options,
        archive => $file
    ) or return undef;

    bless($pack, $class);
}

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

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

sub list_archive {
    foreach my $archive (@_) {
        my $pack = Packdrakeng->open(archive => $archive) or next;
        $pack->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->new(
        archive => $archive,
        compress => $compress,
        uncompress => $uncompress,
        block_size => $size,
        comp_level => $comp_level,
    ) or return;
    while (my $line = <$listh>) {
        chomp($line);
        $pack->add($dir, $line) or return;
    }
    1;
}

sub cat_archive {
    foreach my $archive (@_) {
        my $pack = Packdrakeng->open(archive => $archive) or next;
        (undef, my $files, undef) = $pack->getcontent();
        foreach (@$files) {
            $pack->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->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<packdrake> is a very simple archive extractor and builder used by Mandrakesoft.

=head1 FUNCTIONS

=over

=item B<new($file, %options)>

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

=item B<< packdrake->extract_archive($dir, @files) >>

Extract files list into the specified directory.

=item B<< packdrake->extract_all_archive($dir) >>

Extract all files into the specified directory.

=item B<packdrake::list_archive(@list)>

List files packed into achives given.

=item B<packdrake::build_archive($input,$dir,$archive,$blocksize,$compress,$uncompress)>

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<packdrake::cat_archive(@files)>

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

=back

=head1 SEE ALSO

L<Packdrakeng>.

=head1 COPYRIGHT

Copyright (C) 2000-2004 Mandrakesoft <nanardon@mandrake.org>

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