2 namespace GuzzleHttp\Psr7;
4 use Psr\Http\Message\StreamInterface;
7 * Lazily reads or writes to a file that is opened only after an IO operation
8 * take place on the stream.
10 class LazyOpenStream implements StreamInterface
12 use StreamDecoratorTrait;
14 /** @var string File to open */
17 /** @var string $mode */
21 * @param string $filename File to lazily open
22 * @param string $mode fopen mode to use when opening the stream
24 public function __construct($filename, $mode)
26 $this->filename = $filename;
31 * Creates the underlying stream lazily when required.
33 * @return StreamInterface
35 protected function createStream()
37 return stream_for(try_fopen($this->filename, $this->mode));