Catmandu-BagIt
view release on metacpan or search on metacpan
for my $file ($bagit->list_files) {
my $stat = [stat($file->path)];
printf " name: %s\n", $file->filename;
printf " size: %s\n", $stat->[7];
printf " last-mod: %s\n", scalar(localtime($stat->[9]));
}
my $file = $bagit->get_file("mydata.txt");
my $fh = $file->open;
while (<$fh>) {
....
}
close($fh);
print "dirty?\n" if $bagit->is_dirty;
if ($bagit->complete) {
print "bag is complete\n";
}
else {
print "bag is not complete!\n";
}
if ($bagit->valid) {
print "bag is valid\n";
}
else {
print "bag is not valid!\n";
}
if ($bagit->is_holey) {
print "bag is holey\n";
}
else {
print "bag isn't holey\n";
}
if ($bagit->errors) {
print join("\n",$bagit->errors);
}
# Write operations
$bagit->add_info('My-Tag','fsdfsdfsdf');
$bagit->add_info('My-Tag',['dfdsf','dfsfsf','dfdsf']);
$bagit->remove_info('My-Tag');
$bagit->add_file("test.txt","my text");
$bagit->add_file("data.pdf", IO::File->new("/tmp/data.pdf"));
$bagit->remove_file("test.txt");
$bagit->add_fetch("http://www.gutenberg.org/cache/epub/1980/pg1980.txt","290000","shortstories.txt");
$bagit->remove_fetch("shortstories.txt");
if ($bagit->errors) {
print join("\n",$bagit->errors);
exit;
}
unless ($bagit->locked) {
$bagit->write("bags/demo04"); # fails when the bag already exists
$bagit->write("bags/demo04", new => 1); # recreate the bag when it already existed
$bagit->write("bags/demo04", overwrite => 1); # overwrites an exiting bag
}
CATMANDU MODULES
* Catmandu::Importer::BagIt
* Catmandu::Exporter::BagIt
* Catmandu::Store::File::BagIt
LARGE FILE SUPPORT
Streaming large files into a BagIt requires a large /tmp directory. The
location of the temp directory can be set with the TMPDIR environmental
variable.
METHODS
new()
new(version => ... , algorithm => 'md5|sha1|sha256|sha512')
Create a new BagIt object
read($directory)
Open an exiting BagIt object and return an instance of BagIt or undef
on failure. In array context the read method also returns all errors as
an array:
my $bagit = Catmandu::BagIt->read("/data/my-bag");
my ($bagit,@errors) = Catmandu::BagIt->read("/data/my-bag");
write($directory, [%options])
Write a BagIt to disk. Options: new => 1 recreate the bag when it
already existed, overwrite => 1 overwrite and existing bag (updating
the changed tags/files);
locked
Check if a process has locked the BagIt. Or, a previous process didn't
complete the write operations.
path()
Return the path to the BagIt.
version()
Return the version of the BagIt.
encoding()
Return the encoding of the BagIt.
size()
Return a human readble string of the expected size of the BagIt (adding
the actual sizes found on disk plus the files that need to be fetched
from the network).
payload_oxum()
Return the actual payload oxum of files found in the package.
is_dirty()
Return true when the BagIt contains changes not yet written to disk.
is_holey()
Return true when the BagIt contains a non emtpy fetch configuration.
is_error()
Return an ARRAY of errors when checking complete, valid and write.
complete()
Return true when the BagIt is complete (all files and manifest files
are consistent).
valid()
Returns true when the BagIt is complete and all checkums match the
files on disk.
list_info_tags()
Return an ARRAY of tag names found in bagit-info.txt.
add_info($tag,$value)
add_info($tag,[$values])
Add an info $tag with a $value.
remove_info($tag)
Remove an info $tag.
( run in 2.065 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )