| 1 |
NAME |
| 2 |
|
| 3 |
Catmandu::FileStore - Namespace for packages that can make files |
| 4 |
persistent |
| 5 |
|
| 6 |
SYNOPSIS |
| 7 |
|
| 8 |
# From the command line |
| 9 |
|
| 10 |
# Export a list of all file containers |
| 11 |
$ catmandu export File::Simple --root t/data to YAML |
| 12 |
|
| 13 |
# Export a list of all files in container '1234' |
| 14 |
$ catmandu export File::Simple --root t/data --bag 1234 to YAML |
| 15 |
|
| 16 |
# Add a file to the container '1234' |
| 17 |
$ catmandu stream /tmp/myfile.txt to File::Simple --root t/data --bag 1234 --id myfile.txt |
| 18 |
|
| 19 |
# Download the file 'myfile.txt' from the container '1234' |
| 20 |
$ catmandu stream File::Simple --root t/data --bag 1234 --id myfile.txt to /tmp/output.txt |
| 21 |
|
| 22 |
# Delete the file 'myfile.txt' from the container '1234' |
| 23 |
$ catmandu delete File::Simple --root t/data --bag 1234 --id myfile.txt |
| 24 |
|
| 25 |
# From Perl |
| 26 |
use Catmandu; |
| 27 |
|
| 28 |
my $store = Catmandu->store('File::Simple' , root => 't/data'); |
| 29 |
|
| 30 |
# List all containers |
| 31 |
$store->index->each(sub { |
| 32 |
my $container = shift; |
| 33 |
|
| 34 |
print "%s\n" , $container->{_id}; |
| 35 |
}); |
| 36 |
|
| 37 |
# Add a new container |
| 38 |
$store->index->add({ _id => '1234' }); |
| 39 |
|
| 40 |
# Get the container |
| 41 |
my $files = $store->index->files('1234'); |
| 42 |
|
| 43 |
# Add a file to the container |
| 44 |
$files->upload(IO::File->new('<foobar.txt'), 'foobar.txt'); |
| 45 |
|
| 46 |
my $file = $files->get('foobar.txt'); |
| 47 |
|
| 48 |
# Stream the contents of a file |
| 49 |
$files->stream(IO::File->new('>foobar.txt'), $file); |
| 50 |
|
| 51 |
# Delete a file |
| 52 |
$files->delete('foobar.txt'); |
| 53 |
|
| 54 |
# Delete a container |
| 55 |
$store->index->delete('1234'); |
| 56 |
|
| 57 |
DESCRIPTION |
| 58 |
|
| 59 |
Each Catmandu::FileStore is a Catmandu::Store and inherits all its |
| 60 |
methods, |
| 61 |
|
| 62 |
A Catmandu::FileStore is package to store and retrieve binary content |
| 63 |
in an filesystem, memory or a network. A Catmandu::FileStore contains |
| 64 |
one or more Catmandu::FileBag which is a kind of folder. |
| 65 |
|
| 66 |
Each Catmandu::FileBag contains one or more files. |
| 67 |
|
| 68 |
One special Catmandu::FileBag is the index and contains the listing of |
| 69 |
all Catmandu::FileBag in the Catmandu::FileStore. |
| 70 |
|
| 71 |
CONFIGURATION |
| 72 |
|
| 73 |
index_bag |
| 74 |
|
| 75 |
The name of the index bag to use when no bag name is give. The index |
| 76 |
bag is a bag containing a listing of all Catmandu::FileBag-s in the |
| 77 |
Store. |
| 78 |
|
| 79 |
my $index = $store->index; |
| 80 |
|
| 81 |
$index->each(sub { |
| 82 |
my $bag = shift; |
| 83 |
|
| 84 |
printf "%s\n" , $bag->{_id}; |
| 85 |
}); |
| 86 |
|
| 87 |
index_class |
| 88 |
|
| 89 |
The default class implementation to use for an index of |
| 90 |
Catmandu::FileBag-s. By default this is the Catmandu::FileStore |
| 91 |
implementation with '::Index' added. |
| 92 |
|
| 93 |
METHODS |
| 94 |
|
| 95 |
bag($name) |
| 96 |
|
| 97 |
Create or retieve a bag with name $name. Returns a Catmandu::FileBag. |
| 98 |
|
| 99 |
index |
| 100 |
|
| 101 |
Returns the index Catmandu::FileBag for the Catmandu::FileStore. |
| 102 |
|
| 103 |
my $index = $store->index; |
| 104 |
|
| 105 |
# Add a new file container |
| 106 |
$index->add({ _id => '1234'}); |
| 107 |
|
| 108 |
# Anf use it... |
| 109 |
my $container = $store->bag('1234'); |
| 110 |
|
| 111 |
$container->upload(IO::File->new('data.txt') , 'data.txt'); |
| 112 |
|
| 113 |
log |
| 114 |
|
| 115 |
Return the current logger. Can be used when creating your own Stores. |
| 116 |
|
| 117 |
E.g. |
| 118 |
|
| 119 |
package Catmandu::Store::Hash; |
| 120 |
|
| 121 |
... |
| 122 |
|
| 123 |
sub generator { |
| 124 |
my ($self) = @_; |
| 125 |
|
| 126 |
$self->log->debug("generating record"); |
| 127 |
... |
| 128 |
} |
| 129 |
|
| 130 |
See also: Catmandu for activating the logger in your main code. |
| 131 |
|
| 132 |
AUTHOR |
| 133 |
|
| 134 |
Patrick Hochstenbach, <patrick.hochstenbach at ugent.be> |
| 135 |
|
| 136 |
Nicolas Steenlant, <nicolas.steenlant at ugent.be> |
| 137 |
|
| 138 |
Nicolas Franck, <nicolas.franck at ugent.be> |
| 139 |
|
| 140 |
SEE ALSO |
| 141 |
|
| 142 |
Catmandu::Store::File::Simple, Catmandu::Store::File::Memory, |
| 143 |
Catmandu::FileBag |
| 144 |
|
| 145 |
LICENSE AND COPYRIGHT |
| 146 |
|
| 147 |
This program is free software; you can redistribute it and/or modify it |
| 148 |
under the terms of either: the GNU General Public License as published |
| 149 |
by the Free Software Foundation; or the Artistic License. |
| 150 |
|
| 151 |
See http://dev.perl.org/licenses/ for more information. |
| 152 |
|