1MongoDB::GridFSBucket::UDsoewrnlCooandtSrtirbeuatme(d3M)PoenrgloDDBo:c:uGmreindtFaStBiuocnket::DownloadStream(3)
2
3
4
6 MongoDB::GridFSBucket::DownloadStream - File handle abstraction for
7 downloading
8
10 version v2.2.2
11
13 # OO API
14 $stream = $bucket->open_download_stream($file_id)
15 while ( my $line = $stream->readline ) {
16 ...
17 }
18
19 # Tied-handle API
20 $fh = $stream->fh;
21 while ( my $line = <$fh> ) {
22 ...
23 }
24
26 This class provides a file abstraction for downloading. You can stream
27 data from an object of this class using method calls or a tied-handle
28 interface.
29
31 file_doc
32 The file document for the file to be downloaded.
33
34 Valid file documents typically include the following fields:
35
36 · _id – a unique ID for this document, typically a BSON::OID object.
37 Legacy GridFS files may store this value as a different type.
38
39 · length – the length of this stored file, in bytes
40
41 · chunkSize – the size, in bytes, of each full data chunk of this
42 file.
43
44 · uploadDate – the date and time this file was added to GridFS,
45 stored as a BSON datetime value and inflated per the bucket's
46 bson_codec attribute.
47
48 · filename – the name of this stored file; this does not need to be
49 unique
50
51 · metadata – any additional application-specific data
52
53 · md5 – DEPRECATED
54
55 · contentType – DEPRECATED
56
57 · aliases – DEPRECATED
58
60 fh
61 my $fh = $downloadstream->fh;
62 while ( <$fh> ) {
63 say($_);
64 }
65
66 Returns a new Perl file handle tied to this instance of DownloadStream
67 that can be operated on with the built-in functions "read", "readline",
68 "getc", "eof", "fileno" and "close".
69
70 Important notes:
71
72 Allowing one of these tied filehandles to fall out of scope will NOT
73 cause close to be called. This is due to the way tied file handles are
74 implemented in Perl. For close to be called implicitly, all tied
75 filehandles and the original object must go out of scope.
76
77 Each file handle retrieved this way is tied back to the same object, so
78 calling close on multiple tied file handles and/or the original object
79 will have the same effect as calling close on the original object
80 multiple times.
81
82 close
83 $stream->close
84
85 Works like the builtin "close".
86
87 Important notes:
88
89 · Calling close will also cause any tied file handles created for the
90 stream to also close.
91
92 · "close" will be automatically called when a stream object is
93 destroyed.
94
95 · Calling "close" repeatedly will warn.
96
97 eof
98 if ( $stream->eof() ) { ... }
99
100 Works like the builtin "eof".
101
102 fileno
103 if ( $stream->fileno() ) { ... }
104
105 Works like the builtin "fileno", but it returns -1 if the stream is
106 open and undef if closed.
107
108 getc
109 $char = $stream->getc();
110
111 Works like the builtin "getc".
112
113 read
114 $data = $stream->read($buf, $length, $offset)
115
116 Works like the builtin "read".
117
118 readline
119 $line = $stream->readline();
120 @lines = $stream->readline();
121
122 Works like the builtin "readline".
123
125 · David Golden <david@mongodb.com>
126
127 · Rassi <rassi@mongodb.com>
128
129 · Mike Friedman <friedo@friedo.com>
130
131 · Kristina Chodorow <k.chodorow@gmail.com>
132
133 · Florian Ragwitz <rafl@debian.org>
134
136 This software is Copyright (c) 2020 by MongoDB, Inc.
137
138 This is free software, licensed under:
139
140 The Apache License, Version 2.0, January 2004
141
142
143
144perl v5.32.0 2020-M0o8n-g1o8DB::GridFSBucket::DownloadStream(3)