NAME

Catmandu::Store::File::BagIt - A Catmandu::FileStore to store files on disk in the BagIt format

SYNOPSIS

# From the command line

# Export a list of all file containers
$ catmandu export File::BagIt --root t/data to YAML

# Export a list of all files in container '1234'
$ catmandu export File::BagIt --root t/data --bag 1234 to YAML

# Add a file to the container '1234'
$ catmandu stream /tmp/myfile.txt to File::BagIt --root t/data --bag 1234 --id myfile.txt

# Download the file 'myfile.txt' from the container '1234'
$ catmandu stream File::BagIt --root t/data --bag 1234 --id myfile.txt to /tmp/output.txt

# Delete the file 'myfile.txt' from the container '1234'
$ catmandu delete File::BagIt --root t/data --bag 1234 --id myfile.txt

# From Perl
use Catmandu;

my $store = Catmandu->store('File::BagIt' , root => 't/data');

my $index = $store->index;

# List all folder
$index->bag->each(sub {
    my $container = shift;

    print "%s\n" , $container->{_id};
});

# Add a new folder
$index->add({ _id => '1234' });

# Get the folder
my $files = $index->files('1234');

# Add a file to the folder
$files->upload(IO::File->new('<foobar.txt'), 'foobar.txt');

# Retrieve a file
my $file = $files->get('foobar.txt');

# Stream the contents of a file
$files->stream(IO::File->new('>foobar.txt'), $file);

# Delete a file
$files->delete('foobar.txt');

# Delete a folder
$index->delete('1234');

DESCRIPTION

Catmandu::Store::File::BagIt is a Catmandu::FileStore implementation to store files in a directory structure. Each Catmandu::FileBag is a deeply nested directory based on the numeric identifier of the bag. E.g.

$store->bag(1234)

is stored as

${ROOT}/000/001/234

In this directory all the Catmandu::FileBag items are stored as flat files.

METHODS

new(root => $path , [ keysize => NUM , uuid => 1])

Create a new Catmandu::Store::File::BagIt with the following configuration parameters:

root

The root directory where to store all the files. Required.

keysize

By default the directory structure is 3 levels deep. With the keysize option a deeper nesting can be created. The keysize needs to be a multiple of 3. All the container keys of a Catmandu::Store::File::BagIt must be integers.

uuid

If the to a true value, then the Simple store will require UUID-s as keys

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.

INHERITED METHODS

This Catmandu::FileStore implements:

Catmandu::FileStore
Catmandu::Droppable

The index Catmandu::Bag in this Catmandu::Store implements:

Catmandu::Bag
Catmandu::FileBag::Index
Catmandu::Droppable

The file Catmandu::Bag in this Catmandu::Store implements:

Catmandu::Bag
Catmandu::FileBag
Catmandu::Droppable

SEE ALSO

Catmandu::Store::File::BagIt::Index, Catmandu::Store::File::BagIt::Bag, Catmandu::Plugin::SideCar, Catmandu::FileStore