NAME

Catmandu::Store::File::FedoraCommons::Bag - Index of all "files" in a Catmandu::Store::File::FedoraCommons "folder"

SYNOPSIS

use Catmandu;

my $store = Catmandu->store('File::FedoraCommons'
                    , baseurl   => 'http://localhost:8080/fedora'
                    , username  => 'fedoraAdmin'
                    , password  => 'fedoraAdmin'
                    , namespace => 'demo'
                    , purge     => 1);

my $index = $store->index;

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

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

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

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

# Get a folder
my $folder = $index->get(1234);

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

$files->each(sub {
    my $file = shift;

    my $name         = $file->_id;
    my $size         = $file->size;
    my $content_type = $file->content_type;
    my $created      = $file->created;
    my $modified     = $file->modified;

    $file->stream(IO::File->new(">/tmp/$name"), file);
});

# Add a file
$files->upload(IO::File->new("<data.dat"),"data.dat");

# or (faster)
$files->upload(IO::File::WithFilename->new("<data.dat"),"data.dat");

# Retrieve a file
my $file = $files->get("data.dat");

# Stream a file to an IO::Handle
$files->stream(IO::File->new(">data.dat"),$file);

# Delete a file
$files->delete("data.dat");

# Delete a folders
$index->delete("1234");

DESCRIPTION

A Catmandu::Store::File::FedoraCommons::Bag contains all "files" available in a Catmandu::Store::File::FedoraCommons FileStore "folder". All methods of Catmandu::Bag, Catmandu::FileBag::Index and Catmandu::Droppable are implemented.

Every Catmandu::Bag is also an Catmandu::Iterable.

FOLDERS

All files in a Catmandu::Store::File::FedoraCommons are organized in "folders". To add a "folder" a new record needs to be added to the Catmandu::Store::File::FedoraCommons::Index :

$index->add({_id => '1234'});

The _id field is the only metadata available in FedoraCommons stores. To add more metadata fields to a FedoraCommons store a Catmandu::Plugin::SideCar is required.

FILES

Files can be accessed via the "folder" identifier:

my $files = $index->files('1234');

Use the upload method to add new files to a "folder". Use the download method to retrieve files from a "folder".

$files->upload(IO::File->new("</tmp/data.txt"),'data.txt');

my $file = $files->get('data.txt');

$files->download(IO::File->new(">/tmp/data.txt"),$file);

METHODS

each(\&callback)

Execute callback on every "file" in the FedoraCommons store "folder". See Catmandu::Iterable for more iterator functions

exists($name)

Returns true when a "file" with identifier $name exists.

add($hash)

Adds a new "file" to the FedoraCommons store "folder". It is very much advised to use the upload method below to add new files

get($id)

Returns a hash containing the metadata of the file. The hash contains:

* _id : the file name
* size : file file size
* content_type : the content_type
* created : the creation date of the file
* modified : the modification date of the file
* _stream: a callback function to write the contents of a file to an L<IO::Handle>

If is very much advised to use the stream method below to retrieve files from the store.

delete($name)

Delete the "file" with name $name, if exists.

delete_all()

Delete all files in this folder.

upload(IO::Handle,$name)

Upload the IO::Handle reference to the FedoraCommons store "folder" and use $name as identifier.

FedoraCommons bags will have a faster upload using IO::File::WithFilename as IO::Handles

stream(IO::Handle,$file)

Write the contents of the $file returned by get to the IO::Handle.

SEE ALSO

Catmandu::Store::File::FedoraCommons::Bag , Catmandu::Store::File::FedoraCommons , Catmandu::FileBag::Index , Catmandu::Plugin::SideCar , Catmandu::Bag , Catmandu::Droppable , Catmandu::Iterable