Cloud Storage Client - Class StreamWrapper (1.37.0)

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

Starting PHP 7.4, this is called when include/require is used on a stream.

Absence of this method presents a warning. https://www.php.net/manual/en/migration74.incompatible.php

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
NameDescription
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
TypeDescription
bool

stream_read

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

Parameter
NameDescription
count int

The number of bytes to read.

Returns
TypeDescription
string

stream_write

Callback handler for when we try to write data to the stream.

Parameter
NameDescription
data string

The data to write

Returns
TypeDescription
intThe number of bytes written.

stream_stat

Callback handler for getting data about the stream.

Returns
TypeDescription
array

stream_eof

Callback handler for checking to see if the stream is at the end of file.

Returns
TypeDescription
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
NameDescription
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
TypeDescription
bool

stream_tell

Callhack handler for inspecting our current position in the stream

Returns
TypeDescription
int

dir_closedir

Callback handler for trying to close an opened directory.

Returns
TypeDescription
bool

dir_opendir

Callback handler for trying to open a directory.

Parameters
NameDescription
path string

The url directory to open

options int

Whether or not to enforce safe_mode

Returns
TypeDescription
bool

dir_readdir

Callback handler for reading an entry from a directory handle.

Returns
TypeDescription
string|bool

dir_rewinddir

Callback handler for rewind the directory handle.

Returns
TypeDescription
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
NameDescription
path string

The url directory to create

mode int

The permissions on the directory

options int

Bitwise mask of options. STREAM_MKDIR_RECURSIVE

Returns
TypeDescription
bool

rename

Callback handler for trying to move a file or directory.

Parameters
NameDescription
from string

The URL to the current file

to string

The URL of the new file location

Returns
TypeDescription
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
NameDescription
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
TypeDescription
bool

stream_cast

Callback handler for retrieving the underlaying resource

Parameter
NameDescription
castAs int

STREAM_CAST_FOR_SELECT|STREAM_CAST_AS_STREAM

Returns
TypeDescription
resource|bool

Callback handler for deleting a file

Parameter
NameDescription
path string

The URL of the file to delete

Returns
TypeDescription
bool

url_stat

Callback handler for retrieving information about a file

Parameters
NameDescription
path string

The URI to the file

flags int

Bitwise mask of options

Returns
TypeDescription
array|bool

stream_flush

Callback handler for fflush() function.

Returns
TypeDescription
bool

static::register

Register a StreamWrapper for reading and writing to Google Storage

Parameters
NameDescription
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
NameDescription
protocol string

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

static::getClient

Get the default client to use for streams.

Parameter
NameDescription
protocol string

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

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