# media-cloud-sync/1.3.0/includes/sdk/s3/GuzzleHttp/Psr7/LazyOpenStream.php

Media Cloud Sync, version 1.3.0. 42 lines.

- Page: https://pluginprobe.com/plugins/media-cloud-sync/1.3.0/code/includes/sdk/s3/GuzzleHttp/Psr7/LazyOpenStream.php
- Raw: https://pluginprobe.com/plugins/media-cloud-sync/1.3.0/raw/includes/sdk/s3/GuzzleHttp/Psr7/LazyOpenStream.php
- Modified: 2025-08-17T07:06:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/media-cloud-sync/1.3.0/code/includes/sdk/s3/GuzzleHttp/Psr7/LazyOpenStream.php#L10-L20`.

```php
<?php

declare (strict_types=1);
namespace Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7;

use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
/**
 * Lazily reads or writes to a file that is opened only after an IO operation
 * take place on the stream.
 */
final class LazyOpenStream implements StreamInterface
{
    use StreamDecoratorTrait;
    /** @var string */
    private $filename;
    /** @var string */
    private $mode;
    /**
     * @var StreamInterface
     */
    private $stream;
    /**
     * @param string $filename File to lazily open
     * @param string $mode     fopen mode to use when opening the stream
     */
    public function __construct(string $filename, string $mode)
    {
        $this->filename = $filename;
        $this->mode = $mode;
        // unsetting the property forces the first access to go through
        // __get().
        unset($this->stream);
    }
    /**
     * Creates the underlying stream lazily when required.
     */
    protected function createStream() : StreamInterface
    {
        return Utils::streamFor(Utils::tryFopen($this->filename, $this->mode));
    }
}

```
