@param string   $action
@param TempFile $tempFile

@return FileInterface
332062
private function handleTempFile($action, TempFile $tempFile)
    {
        $volume = $this->volumeManager->getByFolderId($tempFile->getFolderId());
        $folder = $volume->findFolder($tempFile->getFolderId());
        $file = null;

        switch ($action) {
            case self::ACTION_SAVE:
                $file = $volume->createFile($folder, $tempFile, array(), $tempFile->getUserId());
                break;

            case self::ACTION_REPLACE:
                $file = $volume->findFile($tempFile->getFileId());
                $volume->replaceFile($file, $tempFile, array(), $tempFile->getUserId());
                break;

            case self::ACTION_KEEP_BOTH:
                $tempFile->setAlternativeName($this->createAlternateFilename($tempFile));
                $file = $volume->createFile($folder, $tempFile, array(), $tempFile->getUserId());
                break;

            case self::ACTION_SAVE_VERSION:
                $file = $volume->findFile($tempFile->getFileId());
                $fileVersion = $volume->createFileVersion($file, $tempFile, array(), $tempFile->getUserId());
                $volume->activateFileVersion($file, $fileVersion, $tempFile->getUserId());
                break;

            case self::ACTION_DISCARD:
            default:
                break;
        }

        $this->tempStorage->remove($tempFile);

        return $file;
    }
1271825
public function addAction(ActionInterface $action)
  {
    $name = $action->getName();
    $value = $action->getValue();
    $type = $action->getType();

    switch ($type) {
      case ActionInterface::ACTION_FUNCTION:
        $this->functions[] = new \Twig_SimpleFunction($name, $value);
        break;
      case ActionInterface::ACTION_FILTER:
        $this->filters[] = new \Twig_SimpleFilter($name, $value);
        break;
      case ActionInterface::ACTION_TEST:
        $this->tests[] = new \Twig_SimpleTest($name, $value);
        break;
      default:
        throw new \Twig_Error("Unknown twig callable type ($type)");
    }
  }
502958
public function makeFile($mode = FileSystemPermission::NORMAL)
    {
        $fileId = $this->generateId();
        $filePath = sys_get_temp_dir() . '/' . $fileId;
        $file = new TemporaryFile($filePath, $mode);

        return $file;
    }
1167359
public function setTempPath(FilePathInterface $tempPath): void
    {
        if (!$tempPath->isDirectory()) {
            throw new InvalidFilePathException('Temp path "' . $tempPath . '" is not a directory.');
        }

        try {
            $this->tempPath = $this->documentRoot->withFilePath($tempPath);
        } catch (FilePathLogicException $e) {
            throw new InvalidFilePathException($e->getMessage());
        }
    }
860806
public function buildResponse($fileName = 'file.tmp', $contentType = null) {

        if(!class_exists('\Symfony\Component\HttpFoundation\Response')) {

            throw new TempFileException('Could not find class "\Symfony\Component\HttpFoundation\Response".');
        }

        try {

            $response = new \Symfony\Component\HttpFoundation\Response();
            $response->setContent($this->getContent());
            $response->setLastModified(new \DateTime());
            $response->headers->set('Content-Disposition', sprintf('attachment; filename=%s', rawurlencode($fileName)));
            $response->headers->set('Content-Length', $this->getSize());
            $response->headers->set('Content-Type', ($contentType === null) ? ($this->detectMime() ?: 'application/octet-stream') : $contentType);

            return $response;
        }
        catch(\Exception $e) {

            throw new TempFileException('Could not create response.', 0, $e);
        }
    }
371163
private function rollbackOpeningFile($temp_file = null)
    {
        flock($this->getFile(), LOCK_UN);
        fclose($this->getFile());
        if(is_resource($temp_file))
        {
            fclose($temp_file);
            unlink($this->getTempFilePath());
        }
    }
1287888
public static function fromFile($path) {

        if(!is_file($path) || !is_readable($path)) {

            throw new TempFileException(sprintf('File %s does not exist or is not readable.', $path));
        }

        $tempFile = new static();
        $tempFile->closeFileHandle();

        if(!copy($path, $tempFile->filePath)) {

            throw new TempFileException(sprintf('Could not read in file %s.', $path));
        }

        $tempFile->openFileHandle('r+');

        return $tempFile;
    }
1211084
public function backup(TempFile $archive = null): TempFile
	{
		$backup[] = $this->database->backupDatabase();
		foreach ($this->dirs as $dir) {
			$backup[] = $dir;
		}

		if ($archive === null) {
			$archive = new TempFile;
		}
		File::zip($backup, (string) $archive);

		return $archive;
	}
1237702
def tmpfile (dir=None, prefix="temp", suffix=None):
    """"""
    return tempfile.mkstemp(suffix=suffix, prefix=prefix, dir=dir)[1]
681720
protected function uploadZipToTemp($file)
    {
        if (!file_exists($file)) {
            throw new Exception(t('Could not transfer to temp directory - file not found.'));
        } else {
            $dir = time();
            copy($file, $this->f->getTemporaryDirectory() . '/'. $dir . '.zip');

            return $dir;
        }
    }
816954
protected function openFileHandle($mode = 'w+') {

        if($this->fileHandle !== null) {

            throw new TempFileException();
        }

        if(!($fileHandle = fopen($this->filePath, $mode))) {

            throw new TempFileException('Could not open file handle to temporary file.');
        }

        $this->fileHandle = $fileHandle;
    }
502676
public function copy(FileInterface $file, DirInterface $directory)
    {
        $newFile = $this->newFile();
        $newFile->setName($file->getName());
        $newFile->setDir($directory);
        $this->fs[$newFile->getPath()] = $newFile;
        return $newFile;
    }
867849
private static function getTemporaryFile() {
        if(is_callable(self::$temp)) {
            $temporaryFile = @call_user_func(self::$temp);
            if(is_string($temporaryFile) && strlen($temporaryFile) && is_writable($temporaryFile)) {
                return $temporaryFile;
            }
        }
        $temporaryDirectory = (is_string(self::$temp) && strlen(self::$temp)) ? self::$temp : sys_get_temp_dir();
        return tempnam($temporaryDirectory, 'Zip');
    }
1261924
def tempfile(self, mode='wb', **args):
        ""
        tf = tempfile.NamedTemporaryFile(mode=mode)
        self.write(tf.name, mode=mode, **args)
        return tfn
575574
protected function sftpUploadFile(): FunctionsInterface
    {
        /* the directory structure on remote host must exist to SFTP */
        if ($this->get('_localFileSize') > 0) {
            $this->get('_sftp')->uploadFile($this->get('_remoteFilePath'), $this->get('_localCacheFilePath'));
        }

        return $this;
    }
154295
public function getAction($file)
    {
        if (!is_dir($this->source_directory) || !isset($this->file_extension, $this->response_type)) {
            throw new Exception("Controller is not configured!");
        }
        $source_file = $this->source_directory . "/" . $file . "." . $this->file_extension;
        if (!is_readable($source_file)) {
            throw new Error404Exception;
        }
        $this->response->setHeader("Content-Type", $this->response_type);
        return $this->view->display($source_file);
    }
30873
public function upload(File $tmpFile)
    {
        $clusterFileName = $this->_generateClusterFileName($tmpFile);

        $dir = $this->rootBasePath;
        $localPath = $this->getClusterDir($clusterFileName);

        $clusterFileSrc = $clusterFileName;

        if ($localPath) {
            $clusterFileSrc = $localPath.DIRECTORY_SEPARATOR.$clusterFileSrc;
        }

        try {
            $dir = new Dir($dir.DIRECTORY_SEPARATOR.$localPath);
            $resultFile = $dir->newFile($clusterFileName);
            $tmpFile->move($resultFile);

        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }

        return $clusterFileSrc;
    }