Cloud Storage Client - Class StreamWrapper (1.41.3)

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'.

See: http://php.net/manual/en/class.streamwrapper.php

Namespace

Google \ Cloud \ Storage

Methods

__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 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

Returns
Type Description
bool

stream_read

Callback handler for when we try to read a certain number of bytes.

Parameter
Name Description
count int

The 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 string

The 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 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

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 string

The url directory to open

options int

Whether 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 string

The url directory to create

mode int

The permissions on the directory

options int

Bitwise 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 string

The URL to the current file

to string

The 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 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.

Returns
Type Description
bool

stream_cast

Callback handler for retrieving the underlaying resource

Parameter
Name Description
castAs int

STREAM_CAST_FOR_SELECT|STREAM_CAST_AS_STREAM

Returns
Type Description
resource|bool

Callback handler for deleting a file

Parameter
Name Description
path string

The URL of the file to delete

Returns
Type Description
bool

url_stat

Callback handler for retrieving information about a file

Parameters
Name Description
path string

The URI to the file

flags int

Bitwise 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 Google\Cloud\Storage\StorageClient

The StorageClient configuration to use.

protocol string

The name of the protocol to use. Defaults to gs.

static::unregister

Unregisters the SteamWrapper

Parameter
Name Description
protocol string

The name of the protocol to unregister. Defaults to gs.

static::getClient

Get the default client to use for streams.

Parameter
Name Description
protocol string

The name of the protocol to get the client for. Defaults to gs.

Returns
Type Description
Google\Cloud\Storage\StorageClient

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: '~'