MongoDownloadStream
PSR-7 wrapper for MongoDB download stream
Constructors / Destructors
| Returns | Signature and Description |
|---|---|
void | __construct()Creates a new MongoDownloadStream |
Instance Methods
| Returns | Signature and Description |
|---|---|
string | Reads all data from the stream into a string, from the beginning to end. |
void | close()Closes the stream and any underlying resources. |
?resource | detach()Separates any underlying resources from the stream. |
bool | eof()Returns true if the stream is at the end of the stream. |
string | Returns the remaining contents in a string |
array | mixed | null | getMetadata()Get stream metadata as an associative array or retrieve a specific key. |
?int | getSize()Get the size of the stream if known. |
bool | Returns whether or not the stream is readable. |
bool | Returns whether or not the stream is seekable. |
bool | Returns whether or not the stream is writable. |
string | read()Read data from the stream. |
void | rewind()Seek to the beginning of the stream. |
void | seek(, )Seek to a position in the stream. |
int | tell()Returns the current position of the file read/write pointer |
int | write()Write data to the stream. |
Method Details
__construct
__construct(ReadableStream $download)Creates a new MongoDownloadStream
| Name | Type | Description |
|---|---|---|
$download | ReadableStream | The download object |
__toString
__toString()Reads all data from the stream into a string, from the beginning to end.
| Type | Description |
|---|---|
string |
close
close()Closes the stream and any underlying resources.
detach
detach()Separates any underlying resources from the stream.
| Type | Description |
|---|---|
?resource | Underlying PHP stream, if any |
eof
eof()Returns true if the stream is at the end of the stream.
| Type | Description |
|---|---|
bool |
getContents
getContents()Returns the remaining contents in a string
| Type | Description |
|---|---|
string |
| Type | Conditions |
|---|---|
RuntimeException | if unable to read or an error occurs while reading. |
getMetadata
getMetadata(?string $key = null)Get stream metadata as an associative array or retrieve a specific key.
The keys returned are identical to the keys returned from PHP's stream_get_meta_data() function.
| Name | Type | Description |
|---|---|---|
$key | ?string | Specific metadata to retrieve. |
| Type | Description |
|---|---|
array | mixed | null | Returns an associative array if no key is provided. Returns a specific key value if a key is provided and the value is found, or null if the key is not found. |
getSize
getSize()Get the size of the stream if known.
| Type | Description |
|---|---|
?int | Returns the size in bytes if known, or null if unknown. |
isReadable
isReadable()Returns whether or not the stream is readable.
| Type | Description |
|---|---|
bool |
isSeekable
isSeekable()Returns whether or not the stream is seekable.
| Type | Description |
|---|---|
bool |
isWritable
isWritable()Returns whether or not the stream is writable.
| Type | Description |
|---|---|
bool |
read
read(int $length)Read data from the stream.
| Name | Type | Description |
|---|---|---|
$length | int | Read up to $length bytes from the object and return them. Fewer than $length bytes may be returned if underlying stream call returns fewer bytes. |
| Type | Description |
|---|---|
string | Returns the data read from the stream, or an empty string if no bytes are available. |
| Type | Conditions |
|---|---|
RuntimeException | if an error occurs. |
rewind
rewind()Seek to the beginning of the stream.
If the stream is not seekable, this method will raise an exception; otherwise, it will perform a seek(0).
- See
- seek()
| Type | Conditions |
|---|---|
RuntimeException | on failure. |
seek
seek(int $offset, int $whence = SEEK_SET)Seek to a position in the stream.
| Name | Type | Description |
|---|---|---|
$offset | int | Stream offset |
$whence | int | Specifies how the cursor position will be calculated based on the seek offset. Valid values are identical to the built-in PHP $whence values for |
| Type | Conditions |
|---|---|
RuntimeException | on failure. |
tell
tell()Returns the current position of the file read/write pointer
| Type | Description |
|---|---|
int | Position of the file pointer |
| Type | Conditions |
|---|---|
RuntimeException | on error. |
write
write(string $string)Write data to the stream.
| Name | Type | Description |
|---|---|---|
$string | string | The string that is to be written. |
| Type | Description |
|---|---|
int | Returns the number of bytes written to the stream. |
| Type | Conditions |
|---|---|
RuntimeException | on failure. |