stream = fsockopen($tmp[0], (int) $tmp[1]); $this->isOpen = true; return; } $this->isPhpStream = str_starts_with($out, 'php://'); if (!$this->isPhpStream && !Filesystem::createDirectory(dirname($out))) { throw new Exception(sprintf('Directory "%s" was not created', dirname($out))); } $this->stream = fopen($out, 'wb'); $this->isOpen = true; } final public function print(string $buffer): void { assert($this->isOpen); assert($this->stream !== false); fwrite($this->stream, $buffer); } final public function flush(): void { if ($this->isOpen && $this->isPhpStream && $this->stream !== false) { fclose($this->stream); $this->isOpen = false; } } }