@param $fileName
@param $path

@throws \RuntimeException
966288
private function extractOneFileInternal($fileName, $path)
    {
        $tmpPath = str_replace($this->getInternalPath(), '', $fileName);

        // We need to create the directory first in case it doesn't exist
        $dir = pathinfo($path.DIRECTORY_SEPARATOR.$tmpPath, PATHINFO_DIRNAME);
        if (!$this->file->exists($dir) && !$this->file->makeDirectory($dir, 0755, true, true)) {
            throw new \RuntimeException('Failed to create folders');
        }

        $toPath = $path.DIRECTORY_SEPARATOR.$tmpPath;
        $fileStream = $this->getRepository()->getFileStream($fileName);
        $this->getFileHandler()->put($toPath, $fileStream);
    }
174807
public static function read($fileName)
    {
        $data = parent::read($fileName);

        $json = json_decode($data, true);

        if (json_last_error()) {
            throw new \RuntimeException(json_last_error_msg());
        }

        return $json;
    }
1366161
public function install($filename, $target)
    {
        if (!file_exists($filename))
        {
            throw new RuntimeException('Template file not found: ' . $filename);
        }

        $target = $this->rootDir . '/' . $target;
        if (!file_exists($target))
        {
            try
            {
                $umask = umask(0000);
                mkdir($target, 0777, true);
                umask($umask);
            }
            catch (Exception $e)
            {
                throw new RuntimeException(
                    'Can not create target directory: ' . $target, null, $e);
            }
        }

        $target .= '/' . basename($filename);

        if (file_exists($target))
        {
            throw new RuntimeException(sprintf('Template "%s" is already installed', $target));
        }

        if (!copy($filename, $target))
        {
            throw new RuntimeException(sprintf('Failed to copy "%s" to "%s"', $filename, $target));
        }
    }
280697
protected function load($filename)
    {
        $this->catalog = array();

        $fp = fopen($filename, 'rb', false);
        if ($fp === false) {
            throw new \RuntimeException("Could not read $filename");
        }

        $data = fread($fp, 20);
        if (strlen($data) != 20) {
            throw new \RuntimeException('Invalid file');
        }

        $magic = substr($data, 0, 4);
        if ($magic === "\x95\x04\x12\xde") {
            $dword = 'N';
        } elseif ($magic === "\xde\x12\x04\x95") {
            $dword = 'V';
        } else {
            throw new \RuntimeException('Invalid file');
        }

        list(, $revision) = unpack("@4/${dword}", $data);

        if ($revision !== 0) {
            throw new \RuntimeException('Invalid file');
        }

        list(, $count, $origOffset, $transOffset) = unpack("@8/${dword}3", $data);

        fseek($fp, $origOffset);
        $origEntries = array();
        for ($i = 0; $i < $count; $i++) {
            $origEntries[] = unpack("${dword}2", fread($fp, 8));
        }

        fseek($fp, $transOffset);
        $transEntries = array();
        for ($i = 0; $i < $count; $i++) {
            $transEntries[] = unpack("${dword}2", fread($fp, 8));
        }

        for ($i = 0; $i < $count; $i++) {
            fseek($fp, $origEntries[$i][2]);
            $msgid = $origEntries[$i][1] > 0 ? fread($fp, $origEntries[$i][1]) : "";
            fseek($fp, $transEntries[$i][2]);
            $translations = $transEntries[$i][1] > 0 ? explode("\x00", fread($fp, $transEntries[$i][1])) : "";

            $ctx = self::NO_CONTEXT;
            if (($pos = strpos($msgid, self::NO_CONTEXT)) !== false) {
                $ctx = (string) substr($msgid, 0, $pos);
                $msgid = (string) substr($msgid, $pos + 1);
            }

            $this->catalog[$ctx][$msgid] = $translations;
        }
    }
649596
public function setFileName($fileName)
	{
		$hasFilename = ($this->fileName !== null);
		
		if ($hasFilename) {
			$previousName = $this->fileName;
			$previousExtension = $this->getExtension();
		}
		
		parent::setFileName($fileName);
		
		if ($hasFilename) {
			
			$newExtension = $this->getExtension();

			if (strcasecmp($previousExtension, $newExtension) !== 0) {

				// restore name back to previous one. Because that's safer.
				parent::setFileName($previousName);

				throw new \RuntimeException('Extension change is not allowed');
			}
		}
	}
276797
public static function fromFile($filename): self
    {
        if (!is_readable($filename) ||
             false === ($str = file_get_contents($filename))) {
            throw new \RuntimeException("Failed to read $filename.");
        }
        return self::fromString($str);
    }
290418
protected function assertFile($name)
    {
        if (strpos($name, '..') !== false) {
            throw new \InvalidArgumentException("File name '$name' isn't valid");
        }
        
        $file = $this->getFilePath($name);
        
        if (!file_exists($file)) {
            throw new \RuntimeException("View file '$file' doesn't exist");
        }
    }
224075
public function set($path, $value)
    {
        list($name, $path) = $this->splitPath($path);

        if (empty($path)) {
            throw new RuntimeException('The root node of config is not writable');
        }

        return $this->load($name)->set($path, $value);
    }
622218
private function lsLegacy(string $path) : array
    {
        $list = [];
        foreach ($this->nlist($path) as $name) {
            $type   = $this->isDir($name) ? 'dir' : 'file';
            $size   = $this->size($name);
            $mtime  = $this->mdtm($name);

            if ($mtime == -1) {
                throw new RuntimeException('FTP server doesnt support \'ftp_mdtm\'');
            }

            $list[] = new File(['name' => $name, 'modify' => $mtime, 'type' => $type, 'size' => $size]);
        }
        return $list;
    }
268681
public function seeFileFound($filename, $path = '')
    {
        if ($path === '' && file_exists($filename)) {
            $this->openFile($filename);
            \PHPUnit\Framework\Assert::assertFileExists($filename);
            return;
        }

        $found = $this->findFileInPath($filename, $path);

        if ($found === false) {
            $this->fail("File \"$filename\" not found at \"$path\"");
        }

        $this->openFile($found);
        \PHPUnit\Framework\Assert::assertFileExists($found);
    }
658127
public function fromPath($path)
    {
        $mimetype = null;

        if (static::isSupported())
        {
            if (!is_file($path)) {
                throw new \RuntimeException('File not found at '.$path);
            }

            if (!is_readable($path)) {
                throw new \RuntimeException('File not readable at '.$path);
            }

            $mimetype = $this->_getMimetype(strtolower(pathinfo($path, PATHINFO_EXTENSION)));
        }

        return $mimetype;
    }
853445
public function deleteFile($fileName) {
        $files = $this->getFiles();
        $success = false;
        foreach ($files as $file) {
            if($file->getRelativePathname() === $fileName){
                if(!$file->isWritable()){
                    throw new RuntimeException(sprintf("The file '%s' is not writable and can not be deleted.",$fileName));
                }
                unlink($file->getRealPath());
                if($file->isReadable()){
                    throw new RuntimeException(sprintf("The file '%s' could not be deleted",$fileName));
                }
                $success = true;
            }
        }
        return $success;
    }
911370
public function setConnectionRoot($path = '')
    {
        $basePath = $path ?: $this->config['root'];

        if ($basePath && (!ftp_chdir($this->connection, $basePath))) {
            throw new RuntimeException('Root is invalid or does not exist: ' . $basePath);
        }

        // Store absolute path for further reference.
        $this->base_directory = ftp_pwd($this->connection);
    }
331191
public static function putContents($filename, $contents)
    {
        $result = file_put_contents($filename, $contents, \LOCK_EX | \LOCK_NB);
        if ($result === false) {
            throw new \RuntimeException("Cannot write the file: " . $filename);
        }
    }
243839
public function mkdir($pathname, $recursive = false)
    {
        if (@mkdir($pathname, 0777, $recursive) === false) {
            throw new RuntimeException(sprintf("Could't create %s", realpath(getcwd()) . $pathname));
        }
    }
489785
protected function assertFileIsReadable(string $fileName): void
    {
        if (!is_file($fileName) || !is_readable($fileName)) {
            throw new InvalidPathException(sprintf('Unable to read the file at %s', $fileName));
        }
    }
559216
public static function read($fileName)
    {
        if (!file_exists($fileName)) {
            throw new RuntimeException($fileName.' not exist');
        }
        if (!is_readable($fileName)) {
            throw new RuntimeException($fileName.' not readable');
        }

        $fh = fopen($fileName, "r");
        $data = fread($fh, filesize($fileName));
        fclose($fh);

        return $data;
    }