logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Catmandu::Store::File::Memory::Index - Index of all "Folders" in a Catmandu::Store::File::Memory

Description

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

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

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);

Folders All Files In A Catmandu::Store::File::Memory Are Organized In "Folders". To Add A "Folder" A New Record

needstobeaddedtotheCatmandu::Store::File::Memory::Index:
           $index->add({_id => '1234'});

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

Inherited Methods

       This Catmandu::Bag implements:

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

perl v5.40.0                                       2025-01-17             Catmandu::Store...::Memory::Index(3pm)

Name

       Catmandu::Store::File::Memory::Index - Index of all "Folders" in a Catmandu::Store::File::Memory

Synopsis

           use Catmandu;

           my $store = Catmandu->store('File::Memory');

           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");

           # 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");

See Also