Mango:...:Writer(3pm)

πŸ“¦
version 1.30 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ Mango::GridFS::Writer ✨

okay so bestie, welcome to Mango::GridFS::Writer πŸ’– this is the Perl doc for it (you know, the 3pm girlies) and honestly? it's giving gridfs but make it fashion πŸ¦‹


🌸 NAME 🌸

Mango::GridFS::Writer β€” it's a GridFS writer, no cap πŸ’…


✨ SYNOPSIS ✨

use Mango::GridFS::Writer;

my $writer = Mango::GridFS::Writer->new(gridfs => $gridfs);

like, that's literally it. two lines. iconic πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

so what does Mango::GridFS::Writer do? it writes files to GridFS. that's the whole vibe. files go in, GridFS holds them, we slay πŸŽ€


🧚 ATTRIBUTES 🧚

Mango::GridFS::Writer implements the following attributes, and yes you need to know all of them, this is not a drill 🫢

  • chunk_size β€” the chunk size in bytes, and it defaults to 261120 which is 255KB in case you were wondering. you can read it or set it:
my $size = $writer->chunk_size;
$writer  = $writer->chunk_size(1024);
  • content_type β€” the content type of the file. like, what kind of file even is this:
my $type = $writer->content_type;
$writer  = $writer->content_type('text/plain');
  • filename β€” the name of the file. bestie needs a name:
my $name = $writer->filename;
$writer  = $writer->filename('foo.txt');
  • gridfs β€” the Mango::GridFS object that this writer belongs to. it's giving committed relationship:
my $gridfs = $writer->gridfs;
$writer    = $writer->gridfs(Mango::GridFS->new);
  • metadata β€” extra info. additional information. the little garnish ✨:
my $data = $writer->metadata;
$writer  = $writer->metadata({foo => 'bar'});

πŸ’… METHODS πŸ’…

Mango::GridFS::Writer inherits all methods from Mojo::Base and then also implements these brand new ones, because it's an overachiever and we love that for it 😌

  • close β€” closes the file, and it hands you back an $oid:
my $oid = $writer->close;

you can also append a callback to perform the operation non-blocking, because we don't wait around in this house:

$writer->close(sub {
  my ($writer, $err, $oid) = @_;
  ...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
  • is_closed β€” checks if the file has been closed. simple. elegant. a yes-or-no queen:
my $success = $writer->is_closed;
  • write β€” writes a chunk. that's the whole job fr fr:
$writer = $writer->write('hello world!');

and yes, you can append a callback to perform the operation non-blocking here too, same energy:

$writer->write('hello world!' => sub {
  my ($writer, $err) = @_;
  ...
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

🌈 SEE ALSO 🌈


lowkey important: if you're doing the non-blocking callback thing, remember the Mojo::IOLoop->start unless Mojo::IOLoop->is_running; line. it's in the docs for a reason, bestie, don't skip it πŸ™ˆ

okay that's the whole page πŸ“ this was perl v5.30.3, dated 2020-06-05, and it's the Mango:...:Writer(3pm) girlies' moment. mwah, go write some files πŸ’‹πŸ«Άβ­