Catman...FileBag(3pm)
π Catmandu::FileBag π
okay so bestie, welcome to the Catman...FileBag(3pm) page, straight out of the User Contributed Perl Documentation collection. This is the glow-up guide to keeping your binary data cute, cozy, and stored. Let's go π
β¨ NAME β¨
Catmandu::FileBag β a Catmandu::FileStore compartment whose whole entire job is to persist binary data. It's giving storage unit but make it slay π
πΈ SYNOPSIS πΈ
Here's the vibe, copy-paste ready, no cap:
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');
Like, look at it. It literally does the whole lifecycle: list, add, get, upload, stream, delete. Main character behavior fr fr. π
π¦ DESCRIPTION π¦
Every single Catmandu::FileBag is a Catmandu::Bag, and it inherits all of its methods. So whatever the Bag can do, this one can do too β it's not a separate species, it's the same icon in a different fit. β¨
π METHODS π
π upload($io, $file_name)
An helper application that adds an IO::Handle named $io to the Catmandu::FileBag. It returns the number of bytes written. So you hand it a handle, you get back a number β that's the whole deal, bestie. π₯
π stream($io, $file)
A helper application that streams the contents of a Catmandu::FileBag item out to an IO::Handle. It returns the number of bytes written. Basically: item goes in, bytes flow out, count comes back. π
π as_string($file)
Returns the contents of the Catmandu::FileBag item as a string. Just a string. A whole string. Slay. β
π as_string_utf8($file)
Returns the contents of the Catmandu::FileBag item as an UTF-8 string. Note the encoding, bestie β this one's not the same as the plain string one, iykyk. π
π SEE ALSO π
Catmandu::FileStoreβ the store this compartment lives inCatmandu::FileBag::Indexβ the index side of the operation
and that's the page!! you understood it, I know you did, you're literally so smart π₯Ή π
This one shipped with perl v5.36.0, dated 2022-12-10 β and it's listed right back under Catman...FileBag(3pm), so if you ever forget where you read all this, the door's right where you left it. bye bestie, go persist some binary data π β¨
π¦ where this page comes from
- debian bookworm: libcatmandu-filestore-perl 1.16-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libcatmandu-filestore-perl 1.16-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms