Storage/src/StreamWrapper.php
public function stream_open($path, $mode, $flags, &$openedPath)
    {
        $client = $this->openPath($path);

        // strip off 'b' or 't' from the mode
        $mode = rtrim($mode, 'bt');

        $options = [];
        if ($this->context) {
            $contextOptions = stream_context_get_options($this->context);
            if (array_key_exists($this->protocol, $contextOptions)) {
                $options = $contextOptions[$this->protocol] ?: [];
            }
        }

        if ($mode == 'w') {
            $this->stream = new WriteStream(null, $options);
            $this->stream->setUploader(
                $this->bucket->getStreamableUploader(
                    $this->stream,
                    $options + ['name' => $this->file]
                )
            );
        } elseif ($mode == 'r') {
            try {
                // Lazy read from the source
                $options['restOptions']['stream'] = true;
                $this->stream = new ReadStream(
                    $this->bucket->object($this->file)->downloadAsStream($options)
                );

                // Wrap the response in a caching stream to make it seekable
                if (!$this->stream->isSeekable() && ($flags & STREAM_MUST_SEEK)) {
                    $this->stream = new CachingStream($this->stream);
                }
            } catch (ServiceException $ex) {
                return $this->returnError($ex->getMessage(), $flags);
            }
        } else {
            return $this->returnError('Unknown stream_open mode.', $flags);
        }

        if ($flags & STREAM_USE_PATH) {
            $openedPath = $path;
        }
        return true;
    }
public function stream_open($path, $mode, $flags, &$openedPath)
    {
        $client = $this->openPath($path);

        // strip off 'b' or 't' from the mode
        $mode = rtrim($mode, 'bt');

        $options = [];
        if ($this->context) {
            $contextOptions = stream_context_get_options($this->context);
            if (array_key_exists($this->protocol, $contextOptions)) {
                $options = $contextOptions[$this->protocol] ?: [];
            }
        }

        if ($mode == 'w') {
            $this->stream = new WriteStream(null, $options);
            $this->stream->setUploader(
                $this->bucket->getStreamableUploader(
                    $this->stream,
                    $options + ['name' => $this->file]
                )
            );
        } elseif ($mode == 'r') {
            try {
                // Lazy read from the source
                $options['restOptions']['stream'] = true;
                $this->stream = new ReadStream(
                    $this->bucket->object($this->file)->downloadAsStream($options)
                );

                // Wrap the response in a caching stream to make it seekable
                if (!$this->stream->isSeekable() && ($flags & STREAM_MUST_SEEK)) {
                    $this->stream = new CachingStream($this->stream);
                }
            } catch (ServiceException $ex) {
                return $this->returnError($ex->getMessage(), $flags);
            }
        } else {
            return $this->returnError('Unknown stream_open mode.', $flags);
        }

        if ($flags & STREAM_USE_PATH) {
            $openedPath = $path;
        }
        return true;
    }
public function stream_open ( $ path , $ mode , $ flags , & $ openedPath ) { $ client = $ this -> openPath ( $ path ) ; // strip off 'b' or 't' from the mode $ mode = rtrim ( $ mode , 'bt' ) ; $ options = [ ] ; if ( $ this -> context ) { $ contextOptions = stream_context_get_options ( $ this -> context ) ; if ( array_key_exists ( $ this -> protocol , $ contextOptions ) ) { $ options = $ contextOptions [ $ this -> protocol ] ? : [ ] ; } } if ( $ mode == 'w' ) { $ this -> stream = new WriteStream ( null , $ options ) ; $ this -> stream -> setUploader ( $ this -> bucket -> getStreamableUploader ( $ this -> stream , $ options + [ 'name' => $ this -> file ] ) ) ; } elseif ( $ mode == 'r' ) { try { // Lazy read from the source $ options [ 'restOptions' ] [ 'stream' ] = true ; $ this -> stream = new ReadStream ( $ this -> bucket -> object ( $ this -> file ) -> downloadAsStream ( $ options ) ) ; // Wrap the response in a caching stream to make it seekable if ( ! $ this -> stream -> isSeekable ( ) && ( $ flags & STREAM_MUST_SEEK ) ) { $ this -> stream = new CachingStream ( $ this -> stream ) ; } } catch ( ServiceException $ ex ) { return $ this -> returnError ( $ ex -> getMessage ( ) , $ flags ) ; } } else { return $ this -> returnError ( 'Unknown stream_open mode.' , $ flags ) ; } if ( $ flags & STREAM_USE_PATH ) { $ openedPath = $ path ; } return true ; }
Callback handler for when a stream is opened. For reads, we need to
download the file to see if it can be opened.

@param string $path The path of the resource to open
@param string $mode The fopen mode. Currently only supports ('r', 'rb', 'rt', 'w', 'wb', 'wt')
@param int $flags Bitwise options STREAM_USE_PATH|STREAM_REPORT_ERRORS|STREAM_MUST_SEEK
@param string $openedPath Will be set to the path on success if STREAM_USE_PATH option is set
@return bool
Callback handler for when a stream is opened . For reads we need to download the file to see if it can be opened .