Catmandu::FileBag(3pm)

NAME
Catmandu::FileBag - A Catmandu::FileStore compartment to persist binary data

SYNOPSIS
    use Catmandu;

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

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

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

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

    # Get the files
    my $files = $store->bag->files('1234');

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

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

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

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

DESCRIPTION
Each Catmandu::FileBag is a Catmandu::Bag and inherits all its methods.

METHODS

  upload($io, $file_name)
An helper application to add an IO::Handle $io to the Catmandu::FileBag. Returns the number of bytes written.

  stream($io, $file)
A helper application to stream the contents of a Catmandu::FileBag item to an IO::Handle. Returns the number of bytes written.

  as_string($file)
Return the contents of the Catmandu::FileBag item as a string.

  as_string_utf8($file)
Return the contents of the Catmandu::FileBag item as an UTF-8 string.

SEE ALSO
Catmandu::FileStore , Catmandu::FileBag::Index