1 | <?php |
||
28 | class MongoDownloadStream implements StreamInterface |
||
29 | { |
||
30 | /** |
||
31 | * @var \MongoDB\GridFS\ReadableStream |
||
32 | */ |
||
33 | private $download; |
||
34 | |||
35 | /** |
||
36 | * Creates a new MongoDownloadStream |
||
37 | * |
||
38 | * @param $download - The download object |
||
39 | */ |
||
40 | public function __construct(\MongoDB\GridFS\ReadableStream $download) |
||
44 | |||
45 | /** |
||
46 | * Reads all data from the stream into a string, from the beginning to end. |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public function __toString(): string |
||
54 | |||
55 | /** |
||
56 | * Closes the stream and any underlying resources. |
||
57 | */ |
||
58 | public function close(): void |
||
62 | |||
63 | /** |
||
64 | * Separates any underlying resources from the stream. |
||
65 | * |
||
66 | * @return resource|null Underlying PHP stream, if any |
||
67 | */ |
||
68 | public function detach() |
||
72 | |||
73 | /** |
||
74 | * Get the size of the stream if known. |
||
75 | * |
||
76 | * @return int|null Returns the size in bytes if known, or null if unknown. |
||
77 | */ |
||
78 | public function getSize(): ?int |
||
82 | |||
83 | /** |
||
84 | * Returns the current position of the file read/write pointer |
||
85 | * |
||
86 | * @return int Position of the file pointer |
||
87 | * @throws \RuntimeException on error. |
||
88 | */ |
||
89 | public function tell(): int |
||
100 | |||
101 | /** |
||
102 | * Returns true if the stream is at the end of the stream. |
||
103 | * |
||
104 | * @return bool |
||
105 | */ |
||
106 | public function eof(): bool |
||
110 | |||
111 | /** |
||
112 | * Returns whether or not the stream is seekable. |
||
113 | * |
||
114 | * @return bool |
||
115 | */ |
||
116 | public function isSeekable(): bool |
||
120 | |||
121 | /** |
||
122 | * Seek to a position in the stream. |
||
123 | * |
||
124 | * @link http://www.php.net/manual/en/function.fseek.php |
||
125 | * @param int $offset Stream offset |
||
126 | * @param int $whence Specifies how the cursor position will be calculated |
||
127 | * based on the seek offset. Valid values are identical to the built-in |
||
128 | * PHP $whence values for `fseek()`. SEEK_SET: Set position equal to |
||
129 | * offset bytes SEEK_CUR: Set position to current location plus offset |
||
130 | * SEEK_END: Set position to end-of-stream plus offset. |
||
131 | * @throws \RuntimeException on failure. |
||
132 | */ |
||
133 | public function seek($offset, $whence = SEEK_SET): void |
||
140 | |||
141 | /** |
||
142 | * Seek to the beginning of the stream. |
||
143 | * |
||
144 | * If the stream is not seekable, this method will raise an exception; |
||
145 | * otherwise, it will perform a seek(0). |
||
146 | * |
||
147 | * @see seek() |
||
148 | * @link http://www.php.net/manual/en/function.fseek.php |
||
149 | * @throws \RuntimeException on failure. |
||
150 | */ |
||
151 | public function rewind(): void |
||
158 | |||
159 | /** |
||
160 | * Returns whether or not the stream is writable. |
||
161 | * |
||
162 | * @return bool |
||
163 | */ |
||
164 | public function isWritable(): bool |
||
168 | |||
169 | /** |
||
170 | * Write data to the stream. |
||
171 | * |
||
172 | * @param string $string The string that is to be written. |
||
173 | * @return int Returns the number of bytes written to the stream. |
||
174 | * @throws \RuntimeException on failure. |
||
175 | */ |
||
176 | public function write($string): int |
||
180 | |||
181 | /** |
||
182 | * Returns whether or not the stream is readable. |
||
183 | * |
||
184 | * @return bool |
||
185 | */ |
||
186 | public function isReadable(): bool |
||
190 | |||
191 | /** |
||
192 | * Read data from the stream. |
||
193 | * |
||
194 | * @param int $length Read up to $length bytes from the object and return |
||
195 | * them. Fewer than $length bytes may be returned if underlying stream |
||
196 | * call returns fewer bytes. |
||
197 | * @return string Returns the data read from the stream, or an empty string |
||
198 | * if no bytes are available. |
||
199 | * @throws \RuntimeException if an error occurs. |
||
200 | */ |
||
201 | public function read($length): string |
||
205 | |||
206 | /** |
||
207 | * Returns the remaining contents in a string |
||
208 | * |
||
209 | * @return string |
||
210 | * @throws \RuntimeException if unable to read or an error occurs while |
||
211 | * reading. |
||
212 | */ |
||
213 | public function getContents(): string |
||
217 | |||
218 | /** |
||
219 | * Get stream metadata as an associative array or retrieve a specific key. |
||
220 | * |
||
221 | * The keys returned are identical to the keys returned from PHP's |
||
222 | * stream_get_meta_data() function. |
||
223 | * |
||
224 | * @link http://php.net/manual/en/function.stream-get-meta-data.php |
||
225 | * @param string $key Specific metadata to retrieve. |
||
226 | * @return array|mixed|null Returns an associative array if no key is |
||
227 | * provided. Returns a specific key value if a key is provided and the |
||
228 | * value is found, or null if the key is not found. |
||
229 | */ |
||
230 | public function getMetadata($key = null) |
||
238 | } |
||
239 |