Reference documentation and code samples for the Cloud Storage Client class StreamWrapper.
A streamWrapper implementation for handling gs://bucket/path/to/file.jpg.
Note that you can only open a file with mode 'r', 'rb', 'rt', 'w', 'wb', 'wt', 'a', 'ab', or 'at'.
Namespace
Google \ Cloud \ StorageMethods
__destruct
Ensure we close the stream when this StreamWrapper is destroyed.
stream_set_option
This is called when include/require is used on a stream.
stream_metadata
This is called when touch is used on a stream. See: https://www.php.net/manual/en/streamwrapper.stream-metadata.php
| Parameters | |
|---|---|
| Name | Description | 
| path | mixed | 
| option | mixed | 
| value | mixed | 
stream_open
Callback handler for when a stream is opened. For reads, we need to download the file to see if it can be opened.
| Parameters | |
|---|---|
| Name | Description | 
| path | stringThe path of the resource to open | 
| mode | stringThe fopen mode. Currently supports ('r', 'rb', 'rt', 'w', 'wb', 'wt', 'a', 'ab', 'at') | 
| flags | intBitwise options STREAM_USE_PATH|STREAM_REPORT_ERRORS|STREAM_MUST_SEEK | 
| openedPath | stringWill be set to the path on success if STREAM_USE_PATH option is set | 
| Returns | |
|---|---|
| Type | Description | 
| bool | |
stream_read
Callback handler for when we try to read a certain number of bytes.
| Parameter | |
|---|---|
| Name | Description | 
| count | intThe number of bytes to read. | 
| Returns | |
|---|---|
| Type | Description | 
| string | |
stream_write
Callback handler for when we try to write data to the stream.
| Parameter | |
|---|---|
| Name | Description | 
| data | stringThe data to write | 
| Returns | |
|---|---|
| Type | Description | 
| int | The number of bytes written. | 
stream_stat
Callback handler for getting data about the stream.
| Returns | |
|---|---|
| Type | Description | 
| array | |
stream_eof
Callback handler for checking to see if the stream is at the end of file.
| Returns | |
|---|---|
| Type | Description | 
| bool | |
stream_close
Callback handler for trying to close the stream.
stream_seek
Callback handler for trying to seek to a certain location in the stream.
| Parameters | |
|---|---|
| Name | Description | 
| offset | intThe stream offset to seek to | 
| whence | intFlag for what the offset is relative to. See: http://php.net/manual/en/streamwrapper.stream-seek.php | 
| Returns | |
|---|---|
| Type | Description | 
| bool | |
stream_tell
Callhack handler for inspecting our current position in the stream
| Returns | |
|---|---|
| Type | Description | 
| int | |
dir_closedir
Callback handler for trying to close an opened directory.
| Returns | |
|---|---|
| Type | Description | 
| bool | |
dir_opendir
Callback handler for trying to open a directory.
| Parameters | |
|---|---|
| Name | Description | 
| path | stringThe url directory to open | 
| options | intWhether or not to enforce safe_mode | 
| Returns | |
|---|---|
| Type | Description | 
| bool | |
dir_readdir
Callback handler for reading an entry from a directory handle.
| Returns | |
|---|---|
| Type | Description | 
| string|bool | |
dir_rewinddir
Callback handler for rewind the directory handle.
| Returns | |
|---|---|
| Type | Description | 
| bool | |
mkdir
Callback handler for trying to create a directory. If no file path is specified, or STREAM_MKDIR_RECURSIVE option is set, then create the bucket if it does not exist.
| Parameters | |
|---|---|
| Name | Description | 
| path | stringThe url directory to create | 
| mode | intThe permissions on the directory | 
| options | intBitwise mask of options. STREAM_MKDIR_RECURSIVE | 
| Returns | |
|---|---|
| Type | Description | 
| bool | |
rename
Callback handler for trying to move a file or directory.
| Parameters | |
|---|---|
| Name | Description | 
| from | stringThe URL to the current file | 
| to | stringThe URL of the new file location | 
| Returns | |
|---|---|
| Type | Description | 
| bool | |
rmdir
Callback handler for trying to remove a directory or a bucket. If the path is empty or '/', the bucket will be deleted.
Note that the STREAM_MKDIR_RECURSIVE flag is ignored because the option cannot
be set via the rmdir() function.
| Parameters | |
|---|---|
| Name | Description | 
| path | stringThe URL directory to remove. If the path is empty or is '/', This will attempt to destroy the bucket. | 
| options | intBitwise mask of options. | 
| Returns | |
|---|---|
| Type | Description | 
| bool | |
stream_cast
Callback handler for retrieving the underlaying resource
| Parameter | |
|---|---|
| Name | Description | 
| castAs | intSTREAM_CAST_FOR_SELECT|STREAM_CAST_AS_STREAM | 
| Returns | |
|---|---|
| Type | Description | 
| resource|bool | |
unlink
Callback handler for deleting a file
| Parameter | |
|---|---|
| Name | Description | 
| path | stringThe URL of the file to delete | 
| Returns | |
|---|---|
| Type | Description | 
| bool | |
url_stat
Callback handler for retrieving information about a file
| Parameters | |
|---|---|
| Name | Description | 
| path | stringThe URI to the file | 
| flags | intBitwise mask of options | 
| Returns | |
|---|---|
| Type | Description | 
| array|bool | |
stream_flush
Callback handler for fflush() function.
| Returns | |
|---|---|
| Type | Description | 
| bool | |
static::register
Register a StreamWrapper for reading and writing to Google Storage
| Parameters | |
|---|---|
| Name | Description | 
| client | StorageClientThe StorageClient configuration to use. | 
| protocol | stringThe name of the protocol to use. Defaults to
 | 
static::unregister
Unregisters the SteamWrapper
| Parameter | |
|---|---|
| Name | Description | 
| protocol | stringThe name of the protocol to unregister. Defaults
to  | 
static::getClient
Get the default client to use for streams.
| Parameter | |
|---|---|
| Name | Description | 
| protocol | stringThe name of the protocol to get the client for.
Defaults to*  | 
| Returns | |
|---|---|
| Type | Description | 
| StorageClient | |
Constants
DEFAULT_PROTOCOL
Value: 'gs'FILE_WRITABLE_MODE
Value: 33206FILE_READABLE_MODE
Value: 33060DIRECTORY_WRITABLE_MODE
Value: 16895DIRECTORY_READABLE_MODE
Value: 16676TAIL_NAME_SUFFIX
Value: '~'