Catman...FileBag(3pm)

πŸ“¦
version 1.16 Β· 4 versions
, in debian bookworm, ubuntu noble

πŸ’– 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 in
  • Catmandu::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