Convert-UUlib
view release on metacpan or search on metacpan
OPT_RBUF set default read I/O buffer size in bytes
OPT_WBUF set default write I/O buffer size in bytes
OPT_AUTOCHECK automatically check file list after every loadfile
Result/Error codes
RET_OK everything went fine
RET_IOERR I/O Error - examine errno
RET_NOMEM not enough memory
RET_ILLVAL illegal value for operation
RET_NODATA decoder didn't find any data
RET_NOEND encoded data wasn't ended properly
RET_UNSUP unsupported function (encoding)
RET_EXISTS file exists (decoding)
RET_CONT continue -- special from ScanPart
RET_CANCEL operation canceled
File States
This code is zero, i.e. "false":
UUFILE_READ Read in, but not further processed
The following state codes are or'ed together:
FILE_MISPART Missing Part(s) detected
FILE_NOBEGIN No 'begin' found
FILE_NOEND No 'end' found
FILE_NODATA File does not contain valid uudata
FILE_OK All Parts found, ready to decode
FILE_ERROR Error while decoding
FILE_DECODED Successfully decoded
FILE_TMPFILE Temporary decoded file exists
Encoding types
UU_ENCODED UUencoded data
B64_ENCODED Mime-Base64 data
XX_ENCODED XXencoded data
BH_ENCODED Binhex encoded
PT_ENCODED Plain-Text encoded (MIME)
QP_ENCODED Quoted-Printable (MIME)
YENC_ENCODED yEnc encoded (non-MIME)
EXPORTED FUNCTIONS
Initializing and cleanup
Initialize is automatically called when the module is loaded and
allocates quite a small amount of memory for todays machines ;) CleanUp
releases that again.
On my machine, a fairly complete decode with DBI backend needs about
10MB RSS to decode 20000 files.
CleanUp
Release memory, file items and clean up files. Should be called
after a decoidng run, if you want to start a new one.
Setting and querying options
$option = GetOption OPT_xxx
SetOption OPT_xxx, opt-value
See the "OPT_xxx" constants above to see which options exist.
Setting various callbacks
SetMsgCallback [callback-function]
SetBusyCallback [callback-function]
SetFileCallback [callback-function]
SetFNameFilter [callback-function]
Call the currently selected FNameFilter
$file = FNameFilter $file
Loading sourcefiles, optionally fuzzy merge and start decoding
($retval, $count) = LoadFile $fname, [$id, [$delflag, [$partno]]]
Load the given file and scan it for encoded contents. Optionally tag
it with the given id, and if $delflag is true, delete the file after
it is no longer necessary. If you are certain of the part number,
you can specify it as the last argument.
A better (usually faster) way of doing this is using the
"SetFNameFilter" functionality.
$retval = Smerge $pass
If you are desperate, try to call "Smerge" with increasing $pass
values, beginning at 0, to try to merge parts that usually would not
have been merged.
Most probably this will result in garbled files, so never do this by
default, except:
If the "OPT_AUTOCHECK" option has been disabled (by default it is
enabled) to speed up file loading, then you *have* to call "Smerge
-1" after loading all files as an additional pre-pass (which is
normally done by "LoadFile").
$item = GetFileListItem $item_number
Return the $item structure for the $item_number'th found file, or
"undef" of no file with that number exists.
The first file has number 0, and the series has no holes, so you can
iterate over all files by starting with zero and incrementing until
you hit "undef".
This function has to walk the linear list of fils on each access, so
if you want to iterate over all items, it is usually faster to use
"GetFileList".
@items = GetFileList
Similar to "GetFileListItem", but returns all files in one go.
Decoding files
$retval = $item->rename ($newname)
Change the ondisk filename where the decoded file will be saved.
$retval = $item->decode_temp
Decode the file into a temporary location, use "$item->infile" to
retrieve the temporary filename.
$retval = $item->remove_temp
Remove the temporarily decoded file again.
$retval = $item->decode ([$target_path])
Decode the file to its destination, or the given target path.
return $1 if /([a-z0-9_\-+.]{3,}\.[a-z]{3,4}(?:.\d+))/i;
# otherwise just pass what we have
()
};
# now read all files in the directory uusrc/*
for (<uusrc/*>) {
my ($retval, $count) = LoadFile ($_, $_, 1);
print "file($_), status(", strerror $retval, ") parts($count)\n";
}
SetOption OPT_SAVEPATH, "uudst/";
# now wade through all files and their source parts
for my $uu (GetFileList) {
print "file ", $uu->filename, "\n";
print " state ", $uu->state, "\n";
print " mode ", $uu->mode, "\n";
print " uudet ", strencoding $uu->uudet, "\n";
print " size ", $uu->size, "\n";
print " subfname ", $uu->subfname, "\n";
print " mimeid ", $uu->mimeid, "\n";
print " mimetype ", $uu->mimetype, "\n";
# print additional info about all parts
print " parts";
for ($uu->parts) {
for my $k (sort keys %$_) {
print " $k=$_->{$k}";
}
print "\n";
}
$uu->remove_temp;
if (my $err = $uu->decode) {
print " ERROR ", strerror $err, "\n";
} else {
print " successfully saved as uudst/", $uu->filename, "\n";
}
}
print "cleanup...\n";
CleanUp;
PERLMULTICORE SUPPORT
This module supports the perlmulticore standard (see
<http://perlmulticore.schmorp.de/> for more info) for the following
functions - generally these are functions accessing the disk and/or
using considerable CPU time:
LoadFile
$item->decode
$item->decode_temp
$item->remove_temp
$item->info
The perl interpreter will be reacquired/released on every callback
invocation, so for performance reasons, callbacks should be avoided if
that is costly.
Future versions might enable multicore support for more functions.
BUGS AND LIMITATIONS
The original uulib library this module uses was written at a time where
main memory of measured in megabytes and buffer overflows as a security
thign didn't exist. While a lot of security fixes have been applied over
the years (includign some defense in depth mechanism that can shield
against a lot of as-of-yet undetected bugs), using this library for
security purposes requires care.
Likewise, file sizes when the uulib library was written were tiny
compared to today, so do not expect this library to handle files larger
than 2GB.
Lastly, this module uses a very "C-like" interface, which means it
doesn't protect you from invalid points as you might expect from "more
perlish" modules - for example, accessing a file item object after
callinbg "CleanUp" will likely result in crashes, memory corruption, or
worse.
AUTHOR
Marc Lehmann <schmorp@schmorp.de>, the original uulib library was
written by Frank Pilhofer <fp@informatik.uni-frankfurt.de>, and later
heavily bugfixed by Marc Lehmann.
SEE ALSO
perl(1), uudeview homepage at <http://www.fpx.de/fp/Software/UUDeview/>.
( run in 1.166 second using v1.01-cache-2.11-cpan-140bd7fdf52 )