MDV::Packdrakeng - Simple Archive Extractor/Builder
use MDV::Packdrakeng; # creating an archive $pack = MDV::Packdrakeng->new(archive => "myarchive.cz"); # Adding a few files $pack->add("/path/", "file1", "file2"); # Adding an unamed file open($handle, "file"); $pack->add_virtual("filename", $handle); close($handle); $pack = undef; # extracting an archive $pack = MDV::Packdrakeng->open(archive => "myarchive.cz"); # listing files $pack->list(); # extracting few files $pack->extract("/path/", "file1", "file2"); # extracting data into a file handle open($handle, "file"); $pack->extract_virtual($handle, "filename"); close($handle);
MDV::Packdrakeng is a simple indexed archive builder and extractor using standard compression methods.
MDV::Packdrakeng
Compressed data are stored by block. For example,
UncompresseddatA1UncompresseddatA2 UncompresseddatA3UncompresseddatA4 |--- size 1 ---||--- size 2 ---| |--- size 3 ---||--- size 4 ---| |<-offset1 |<-offset2 |<-offset3 |<-offset4
gives:
CompresseD1CompresseD2 CompresseD3CompresseD4 |--- c. size 1, 2 ---| |--- c. size 3, 4 ---| |<-c. offset 1, 2 |<-c. offset 3, 4
A new block is started when its size exceeds the block_size value.
block_size
Compressed data are followed by the table of contents (toc), that is, a simple list of packed files. Each file name is terminated by the \n character:
\n
dir1 dir2 ... dirN symlink1 point_file1 symlink2 point_file2 ... ... symlinkN point_fileN file1 file2 ... fileN
The file sizes follows, 4 values are stored for each file: offset into archive of compressed block, size of compressed block, offset into block of the file and the file's size.
Finally the archive contains a 64-byte trailer, about the toc and the archive itself:
'cz[0', strings 4 bytes number of directory, 4 bytes number of symlinks, 4 bytes number of files, 4 bytes the toc size, 4 bytes the uncompression command, string of 40 bytes length '0]cz', string 4 bytes
Creates a new archive. Options:
The file name of the archive. If the file doesn't exist, it will be created, else it will be owerwritten. See open.
open
The application to use to compress, if unspecified, gzip is used.
The application used to extract data from archive. This option is useless if you're opening an existing archive (unless you want to force it). If unset, this value is based on compress command followed by '-d' argument.
If you're using gzip, by default MDV::Packdrakeng will use perl-zlib to save system ressources. This option forces MDV::Packdrakeng to use the external gzip command. This has no meaning with other compress programs as internal functions are not implemented yet.
The compression level passed as an argument to the compression program. By default, this is set to 6.
The limit size after which we start a new compressed block. The default value is 400KB. Set it to 0 to be sure a new block will be started for each packed files, and -1 to never start a new block. Be aware that a big block size will slow down the file extraction.
Do not output anything, shut up.
Print debug messages.
Opens an existing archive for extracting or adding files.
The uncompression command is found into the archive, and the compression command is deduced from it.
If you add files, a new compressed block will be started even if the last block is smaller than the value of the block_size option. If some compression options can't be found in the archive, the new preference will be applied.
Options are the same than for the new() function.
new()
Adds a file into archive according passed information. $type gives the type of the file:
- 'd', the file will be a directory, store as '$filename'. $data is not used. - 'l', the file will be a symlink named $filename, pointing to the file whose path is given by the string $data. - 'f', the file is a normal file, $filename will be its name, $data is either an handle to open file, data will be read from current position to the end of file, either a string to push as the content of the file.
Adds @files into archive located into $prefix. Only directory, files and symlink will be added. For each file, the path should be relative to $prefix and is stored as is.
Extracts $filename data from archive into the *HANDLE. $filename should be a normal file.
Extracts @files from the archive into $destdir prefix.
Returns three arrayrefs describing files files into archive, respectively directory list, files list and symlink list.
Returns type and information about a given file into the archive; that is:
- 'f' and the the size of the file for a plain file - 'l' and the linked file for a symlink - 'd' and undef for a directory - undef if the file can't be found into archive.
Print to $handle (STDOUT if not specified) the content of the archive.
Print to $handle (STDOUT if not specified) the table of content of the archive.
Olivier Thauvin <nanardon@mandriva.org>, Rafael Garcia-Suarez <rgarciasuarez@mandriva.com>
Copyright (c) 2005 Mandriva
This module is a from scratch-rewrite of the original packdrake utility. Its format is fully compatible with the old packdrake.
packdrake
This program is free software; you can redistribute it and/or modify it under the terms of GNU General Public License as published by the Free Software Foundation; either version 2 of the License, 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.
If you do not have a copy of the GNU General Public License write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
To install MDV::Packdrakeng, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MDV::Packdrakeng
CPAN shell
perl -MCPAN -e shell install MDV::Packdrakeng
For more information on module installation, please visit the detailed CPAN module installation guide.