MongoDB::GridFSBucket::DownloadStream(3pm) | User Contributed Perl Documentation | MongoDB::GridFSBucket::DownloadStream(3pm) |
MongoDB::GridFSBucket::DownloadStream - File handle abstraction for downloading
version v2.2.2
# OO API $stream = $bucket->open_download_stream($file_id) while ( my $line = $stream->readline ) { ... } # Tied-handle API $fh = $stream->fh; while ( my $line = <$fh> ) { ... }
This class provides a file abstraction for downloading. You can stream data from an object of this class using method calls or a tied-handle interface.
The file document for the file to be downloaded.
Valid file documents typically include the following fields:
my $fh = $downloadstream->fh; while ( <$fh> ) { say($_); }
Returns a new Perl file handle tied to this instance of DownloadStream that can be operated on with the built-in functions "read", "readline", "getc", "eof", "fileno" and "close".
Important notes:
Allowing one of these tied filehandles to fall out of scope will NOT cause close to be called. This is due to the way tied file handles are implemented in Perl. For close to be called implicitly, all tied filehandles and the original object must go out of scope.
Each file handle retrieved this way is tied back to the same object, so calling close on multiple tied file handles and/or the original object will have the same effect as calling close on the original object multiple times.
$stream->close
Works like the builtin "close".
Important notes:
if ( $stream->eof() ) { ... }
Works like the builtin "eof".
if ( $stream->fileno() ) { ... }
Works like the builtin "fileno", but it returns -1 if the stream is open and undef if closed.
$char = $stream->getc();
Works like the builtin "getc".
$data = $stream->read($buf, $length, $offset)
Works like the builtin "read".
$line = $stream->readline(); @lines = $stream->readline();
Works like the builtin "readline".
This software is Copyright (c) 2020 by MongoDB, Inc.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
2022-06-30 | perl v5.34.0 |