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
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.
path
string
The path of the resource to open
mode
string
The fopen mode. Currently supports ('r', 'rb', 'rt', 'w', 'wb', 'wt', 'a', 'ab', 'at')
flags
int
Bitwise options STREAM_USE_PATH|STREAM_REPORT_ERRORS|STREAM_MUST_SEEK
openedPath
string
Will be set to the path on success if STREAM_USE_PATH option is set
bool
stream_read
Callback handler for when we try to read a certain number of bytes.
count
int
The number of bytes to read.
string
stream_write
Callback handler for when we try to write data to the stream.
data
string
The data to write
int
stream_stat
Callback handler for getting data about the stream.
array
stream_eof
Callback handler for checking to see if the stream is at the end of file.
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.
offset
int
The stream offset to seek to
whence
int
Flag for what the offset is relative to. See: http://php.net/manual/en/streamwrapper.stream-seek.php
bool
stream_tell
Callhack handler for inspecting our current position in the stream
int
dir_closedir
Callback handler for trying to close an opened directory.
bool
dir_opendir
Callback handler for trying to open a directory.
path
string
The url directory to open
options
int
Whether or not to enforce safe_mode
bool
dir_readdir
Callback handler for reading an entry from a directory handle.
string|bool
dir_rewinddir
Callback handler for rewind the directory handle.
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.
path
string
The url directory to create
mode
int
The permissions on the directory
options
int
Bitwise mask of options. STREAM_MKDIR_RECURSIVE
bool
rename
Callback handler for trying to move a file or directory.
from
string
The URL to the current file
to
string
The URL of the new file location
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.
path
string
The URL directory to remove. If the path is empty or is '/', This will attempt to destroy the bucket.
options
int
Bitwise mask of options.
bool
stream_cast
Callback handler for retrieving the underlaying resource
castAs
int
STREAM_CAST_FOR_SELECT|STREAM_CAST_AS_STREAM
resource|bool
unlink
Callback handler for deleting a file
path
string
The URL of the file to delete
bool
url_stat
Callback handler for retrieving information about a file
path
string
The URI to the file
flags
int
Bitwise mask of options
array|bool
stream_flush
Callback handler for fflush() function.
bool
static::register
Register a StreamWrapper for reading and writing to Google Storage
client
protocol
string
The name of the protocol to use. Defaults to gs
.
static::unregister
Unregisters the SteamWrapper
protocol
string
The name of the protocol to unregister. Defaults
to gs
.
static::getClient
Get the default client to use for streams.
protocol
string
The name of the protocol to get the client for. Defaults to gs
.
Constants
DEFAULT_PROTOCOL
Value: 'gs'
FILE_WRITABLE_MODE
Value: 33206
FILE_READABLE_MODE
Value: 33060
DIRECTORY_WRITABLE_MODE
Value: 16895
DIRECTORY_READABLE_MODE
Value: 16676
TAIL_NAME_SUFFIX
Value: '~'