Creates an instance from a resource.
@param string   $filename    File name.
@param resource $fileHandler File handler.

@throws FileCorruptedException

@return FileHeader
172950
public static function createFromResource($filename, $fileHandler)
    {
        $header = new FileHeader();

        $data = unpack("nmagicNumber/C1compressionMethod/C1flags/LmodificationTime/C1extraFlags/C1os", fread($fileHandler, 10));

        // check magic number and compression method
        if (self::MAGIC_NUMBER !== $data['magicNumber'] ||
            self::COMPRESSION_METHOD_DEFLATE !== $data['compressionMethod']) {
            throw new FileCorruptedException($filename);
        }

        $header
            ->setCompressionMethod($data['compressionMethod'])
            ->setFlags($data['flags'])
            ->setExtraFlags($data['extraFlags'])
            ->setModificationTimeFromUnixEpoch($data['modificationTime'])
            ->setOperatingSystem($data['os']);

        // if FLG.FEXTRA set
        if (($header->getFlags() & self::FLAGS_EXTRA) === self::FLAGS_EXTRA) {
            $extraFieldData = unpack("C2subfield/vlength", fread($fileHandler, 10));

            $header
                ->setExtraSubfields($extraFieldData['subfield1'], $extraFieldData['subfield2'])
                ->setExtraData(fread($fileHandler, $extraFieldData['length']));
        }

        // if FLG.FNAME set
        if (($header->getFlags() & self::FLAGS_NAME) === self::FLAGS_NAME) {
            $header->setOriginalFilename(self::readString($fileHandler));
        }

        // if FLG.FCOMMENT set
        if (($header->getFlags() & self::FLAGS_COMMENT) === self::FLAGS_COMMENT) {
            $header->setComment(self::readString($fileHandler));
        }

        // if FLG.FHCRC set
        if (($header->getFlags() & self::FLAGS_HCRC) === self::FLAGS_HCRC) {
            $crcData = unpack('vcrc', fread($fileHandler, 2));
            $header->setCrc16($crcData['crc']);
        }

        return $header;
    }
721363
public static function createStreamFromFile($filename, $mode = 'r')
    {
        if (! static::$streamFactory) {
            static::$streamFactory = new StreamFactory();
        }

        return static::$streamFactory->createStreamFromFile($filename, $mode);
    }
784993
public function getFileHandler($extension)
    {
        if (array_key_exists($extension, $this->fileHandler)) {
            //@todo check for interface
            //@todo use factory here
            return GeneralUtility::makeInstance($this->fileHandler[$extension]);
        } else {
            return;
        }
    }
225818
public static function createFromFile(string $filename, string $contentType = null): self
    {
        $instance = new static();
        $instance->content = \file_get_contents($filename);
        $instance->name = \basename($filename);

        if (null !== $contentType) {
            $instance->contentType = $contentType;
        }

        return $instance;
    }
716178
public function create($fileUri, $agendaId, $filename, $type = Document::DOCTYPE_PURCHASE, $fileSplit = false, $lacyLoad = false): Document
    {
        $file = new FileInfo($fileUri);
        $mimeType = $file->getMimeType();

        $documentFile = new DocumentFile();
        $documentFile->setType($type)
            ->setAgendaId($agendaId)
            ->setFileSplit($fileSplit)
            ->setFile(
                new UploadFile($file->getFilename(), $mimeType, file_get_contents($file->getPathname()))
            )
        ;

        return current($this->send([$documentFile], $lacyLoad));
    }
36029
protected function createOrUpdateDocument($resource, $name, $filename)
    {
        if (request()->hasFile('file')) {

            // create or update
            if (is_null($resource->document)) {
                $resource->documents()->create([
                    'name'     => $name,
                    'filename' => $filename,
                ]);
            }
            else {
                // update the document entry
                $resource->document->update([
                    'name'     => $name,
                    'filename' => $filename,
                ]);
            }
        }
    }
582556
public function parse($filename, ProjectDescriptorBuilder $builder)
    {
        if (class_exists('phpDocumentor\Event\Dispatcher')) {
            Dispatcher::getInstance()->dispatch(
                'parser.file.pre',
                PreFileEvent::createInstance($this)->setFile($filename)
            );
        }
        $this->log('Starting to parse file: ' . $filename);

        try {
            $file = $this->createFileReflector($builder, $filename);
            if (!$file) {
                $this->log('>> Skipped file ' . $filename . ' as no modifications were detected');
                return;
            }

            $file->process();
            $builder->buildFileUsingSourceData($file);
            $this->logErrorsForDescriptor($builder->getProjectDescriptor()->getFiles()->get($file->getFilename()));
        } catch (Exception $e) {
            $this->log(
                '  Unable to parse file "' . $filename . '", an error was detected: ' . $e->getMessage(),
                LogLevel::ALERT
            );
        }
    }
178968
public static function fromFile(string $filename): PhpClass {
		$class = new PhpClass();
		$parser = new FileParser($filename);
		$parser->addVisitor(new ClassParserVisitor($class));
		$parser->addVisitor(new MethodParserVisitor($class));
		$parser->addVisitor(new ConstantParserVisitor($class));
		$parser->addVisitor(new PropertyParserVisitor($class));
		$parser->parse();

		return $class;
	}
380595
public function fromFile(string $filename = '', bool $returnArray = false)
    {
        if (empty($filename)) {
            throw new InvalidArgumentException('File name must be specified');
        }

        \set_error_handler(
            function ($error, $message = '') use ($filename) {
                $exMsg = \sprintf('Error reading from "%s": %s', $filename, $message);
                throw new RuntimeException($exMsg, $error);
            },
            E_WARNING
        );

        try {
            $config = $this->transform(\file_get_contents($filename));
            \restore_error_handler();
            return $returnArray ? $config : new Config($config);
        } catch (RuntimeException $e) {
            \restore_error_handler();
            throw $e;
        }
    }
951094
public static function me($fileName='', $separate='/')
    {
        if (self::$instance === null) {
            self::$instance = self::load($fileName, $separate);
        }

        return self::$instance;
    }
175395
public static function fromFile(string $filename = ''): self
    {
        if (!\file_exists($filename)) {
            throw new \Exception($filename.' does not exist');
        }
        $contents = \file_get_contents($filename);
        if (!\is_string($contents)) {
            throw new \Exception('Could not read file contents');
        }
        return self::fromData($contents);
    }
957700
public static function badFileName(
        string $fileName, 
        \Exception $previous = null
    ): self {
        return new self(
            "bad file name: {$fileName}",
            self::BAD_FILE_NAME,
            $previous
        );
    }
546244
private function fileLineGenerator(string $fileName, callable $formatter = null)
    {
        $f = fopen($fileName, 'r');
        try {
            while ($line = fgets($f)) {
                if(!is_null($formatter)){
                    yield call_user_func($formatter, $line);
                }
                else {
                    yield $line;
                }
            }
        } finally {
            fclose($f);
        }
    }
441050
public function upload(FileResource $file)
    {
        $path = $this->buildAttachmentsPath();
        $builder = (new MultipartStreamBuilder())->addResource($file->getName(), $file->getResource(), $file->getOptions());
        $headers = ['Content-Type' => sprintf('multipart/form-data; boundary="%s"', $builder->getBoundary())];

        return $this->postRaw($path, $builder->build(), $headers);
    }
245318
public function create($filename, $width, $height = null)
    {
        try {
            $image = app('image')->make($this->file->realPath)
                ->fit($width, ($height ?: $width))
                ->encode();

            $this->file->storage->put($this->file->path($filename), $image);
        } catch (NotReadableException $e) {
            return null;
        }

        return $this->file->storage->url($this->file->path($filename));
    }
1138729
protected function loadFile($filename)
    {
        // Save this so we can modify it and still delegate to parent
        $originalFilename = $filename;

        if (isset($this->aliases[$filename])) {
            $filename = $this->aliases[$filename];
        }

        if ($this->isModular($filename)) {
            // Description is modular, this class should handle it
            return $this->loadModular($filename);
        }

        // Description isn't modular, delegate to parent with the
        // original (unmodified) value of $filename
        return parent::loadFile($originalFilename);
    }
327406
public static function csvFileToArrayGenerator(string $filename = '', string $delimiter = ',')
    {
        $complete = false;
        try {
            $header = null;
            if (($handle = fopen($filename, 'r')) !== false) {
                while (($row = fgetcsv($handle, 4096, $delimiter)) !== false) {
                    if (!$header) {
                        $header = $row;
                    } else {
                        yield array_combine($header, $row);
                    }
                }
            }
            $complete = true;
        } finally {
            if (!$complete) {
                // cleanup when loop breaks
            } else {
                // cleanup when loop completes
            }
        }
        // Do something only after loop completes
    }