creates an input stream for given source

@param   mixed  $source   source to create input stream from
@param   array  $options  list of options for the input stream
@return  \stubbles\streams\file\FileInputStream
763652
public function createInputStream($source, array $options = []): InputStream
    {
        if (isset($options['filemode'])) {
            return new FileInputStream($source, $options['filemode']);
        }

        return new FileInputStream($source);
    }
547970
public function appendFile($source, $index = 0)
    {
        $chunkFile = $this->chunkFile().'.'.$index;
        $this->files->appendStream($chunkFile, $source, 0);

        return $this;
    }
1349385
public function stream($filename = "document.pdf", $options = array())
    {
        if (headers_sent()) {
            die("Unable to stream pdf: headers already sent");
        }

        if (!isset($options["compress"])) $options["compress"] = true;
        if (!isset($options["Attachment"])) $options["Attachment"] = true;

        $this->_add_page_text();

        $debug = !$options['compress'];
        $tmp = ltrim($this->_pdf->output($debug));

        header("Cache-Control: private");
        header("Content-Type: application/pdf");
        header("Content-Length: " . mb_strlen($tmp, "8bit"));

        $filename = str_replace(array("\n", "'"), "", basename($filename, ".pdf")) . ".pdf";
        $attachment = $options["Attachment"] ? "attachment" : "inline";
        header(Helpers::buildContentDispositionHeader($attachment, $filename));

        echo $tmp;
        flush();
    }
600676
public function file(array &$submitted, array $options = array())
    {
        $this->options = $options;
        $this->submitted = &$submitted;

        $this->validateFile();
        $this->validateTitleFile();
        $this->validateDescription();
        $this->validateWeight();
        $this->validateTranslation();
        $this->validateUploadFile();
        $this->validatePathFile();
        $this->validateEntityFile();
        $this->validateEntityIdFile();
        $this->validateFileTypeFile();
        $this->validateMimeTypeFile();

        $this->unsetSubmitted('update');

        return $this->getResult();
    }
814257
public function getDataSource(string  $source) : Source
	{
		switch ($source) {
			case 'form':
			case 'forms':
				return $this
					->getDataSources()
					->getFormsDataSource();
				break;
			case 'entry':
			case 'entries':
				return $this
					->getDataSources()
					->getEntryDataSource();
				break;
			case 'entryValue':
			case 'entryValues':
				return $this
					->getDataSources()
					->getEntryValuesDataSource();
		}
	}
332317
public function getOutput($input, array $options = array())
    {
        $this->log(sprintf('Getting output from file (%s)', $input));

        return $this->getGenerator()->getOutput($input, $options);
    }
318785
private function determineSource($source)
    {
        // Use the contents of a file as the data source.
        if (is_string($source)) {
            $source = Psr7\try_fopen($source, 'r');
        }

        // Create a source stream.
        $stream = Psr7\stream_for($source);
        if (!$stream->isReadable()) {
            throw new IAE('Source stream must be readable.');
        }

        return $stream;
    }
999087
public static function serveOriginal($source, $options)
    {
        $contentType = ImageMimeTypeGuesser::lenientGuess($source);
        if (is_null($contentType)) {
            throw new ServeFailedException('Rejecting to serve original (mime type cannot be determined)');
        } elseif ($contentType === false) {
            throw new ServeFailedException('Rejecting to serve original (it is not an image)');
        } else {
            ServeFile::serve($source, $contentType, $options);
        }
    }
374449
public static function compile(Context $context, Source $source, int $options = ScriptCompiler::OPTION_NO_COMPILE_OPTIONS): Script
    {
    }
163605
public function aggregate($source, $pipeline, $options = [])
    {
        if ($pos = strpos($source, '.')) {
            $db = substr($source, 0, $pos);
            $collection = substr($source, $pos + 1);
        } else {
            $db = $this->_default_db;
            $collection = $source;
        }

        try {
            $command = ['aggregate' => $collection, 'pipeline' => $pipeline];
            if ($options) {
                $command = array_merge($command, $options);
            }
            if (!isset($command['cursor'])) {
                $command['cursor'] = ['batchSize' => 1000];
            }
            return $this->command($command, $db);
        } catch (RuntimeException $e) {
            throw new MongodbException([
                '`:aggregate` aggregate for `:collection` collection failed: :msg',
                'aggregate' => json_encode($pipeline),
                'collection' => $source,
                'msg' => $e->getMessage()
            ]);
        }
    }
867659
public static function file($name, $options = [])
    {
        self::exclure($options);

        return self::input('file', $name, null, $options);
    }
47034
public function parse($source, array $options = null) {
		$result = simplexml_load_string($source);
		
		if ($result === false) {
			throw new InvalidContent('Unable to parse the XML content');
		}
		
		return $this->simpleXmlToArray($result);
	}
999987
public static function create($params = null, $options = null)
    {
        $opts = \Stripe\Util\RequestOptions::parse($options);
        if (is_null($opts->apiBase)) {
            $opts->apiBase = Stripe::$apiUploadBase;
        }
        // Manually flatten params, otherwise curl's multipart encoder will
        // choke on nested arrays.
        // TODO: use array_column() once we drop support for PHP 5.4
        $flatParams = [];
        foreach (\Stripe\Util\Util::flattenParams($params) as $pair) {
            $flatParams[$pair[0]] = $pair[1];
        }
        return static::_create($flatParams, $opts);
    }
903868
public function createDocumentFromSource($source)
    {
        if ($source instanceof \DOMDocument) {
            return $source;
        }

        throw new RuntimeException(RuntimeException::INVALID_DOM_SOURCE_STR, RuntimeException::INVALID_DOM_SOURCE);
    }
784608
protected function _process(File $file, array $options) {
        if (!$file->isImage()) {
            throw new DomainException(sprintf('%s is not a valid image', $file->basename()));
        }

        $sourcePath = $file->path();
        $mimeType = $file->type();

        // Create an image to work with
        switch ($mimeType) {
            case 'image/gif':
                $sourceImage = @imagecreatefromgif($sourcePath);
            break;
            case 'image/png':
                $sourceImage = @imagecreatefrompng($sourcePath);
            break;
            case 'image/jpg':
            case 'image/jpeg':
            case 'image/pjpeg':
                $sourceImage = @imagecreatefromjpeg($sourcePath);
            break;
            default:
                $sourceImage = false;
            break;
        }

        if (!$sourceImage) {
            throw new DomainException(sprintf('%s can not be transformed', $mimeType));
        }

        // Gather options
        $options = $options + array(
            'width' => null,
            'height' => null,
            'dest_x' => 0,
            'dest_y' => 0,
            'dest_w' => null,
            'dest_h' => null,
            'source_x' => 0,
            'source_y' => 0,
            'source_w' => $file->width(),
            'source_h' => $file->height(),
            'quality' => 100,
            'overwrite' => false,
            'target' => '',
            'preCallback' => '',
            'postCallback' => ''
        );

        $options = array_map(function($value) {
            if (is_numeric($value)) {
                $value = round($value);
            }

            return $value;
        }, $options);

        $width = $options['width'] ?: $options['dest_w'];
        $height = $options['height'] ?: $options['dest_h'];
        $targetImage = imagecreatetruecolor($width, $height);

        // If gif/png allow transparencies
        if ($mimeType === 'image/gif' || $mimeType === 'image/png') {
            imagealphablending($targetImage, false);
            imagesavealpha($targetImage, true);
            imagefill($targetImage, 0, 0, imagecolorallocatealpha($targetImage, 255, 255, 255, 127));
        }

        // Trigger a callback to prepare the image
        if (is_callable($options['preCallback'])) {
            $targetImage = call_user_func_array($options['preCallback'], array($targetImage, $options));
        }

        // Lets take our source and apply it to the temporary file and resize
        imagecopyresampled($targetImage, $sourceImage, $options['dest_x'], $options['dest_y'], $options['source_x'], $options['source_y'], $options['dest_w'], $options['dest_h'], $options['source_w'], $options['source_h']);

        // Trigger a callback to modify the image
        if (is_callable($options['postCallback'])) {
            $targetImage = call_user_func_array($options['postCallback'], array($targetImage, $options));
        }

        // Now write the transformed image to the server
        if ($options['overwrite']) {
            $options['target'] = $file->name();

        } else if (!$options['target']) {
            $class = explode('\\', get_class($this));
            $class = str_replace('transformer', '', strtolower(end($class)));

            $options['target'] = sprintf('%s-%s-%sx%s-%s', $file->name(), $class, $width, $height, uniqid());
        }

        $targetPath = sprintf('%s%s.%s', $file->dir(), $options['target'], $file->ext());

        switch ($mimeType) {
            case 'image/gif':
                imagegif($targetImage, $targetPath);
            break;
            case 'image/png':
                imagepng($targetImage, $targetPath);
            break;
            case 'image/jpg':
            case 'image/jpeg':
            case 'image/pjpeg':
                imagejpeg($targetImage, $targetPath, $options['quality']);
            break;
        }

        // Clear memory
        imagedestroy($sourceImage);
        imagedestroy($targetImage);

        return new File($targetPath);
    }
389349
public function pipeAll(ReadableStreamInterface $source, WritableStreamInterface $destination, array $options = [])
    {
        // TODO: use stream_copy_to_stream
        // it is 4x faster than this
        // but can lose data under load with no way to recover it
        $destination->emit('pipe', array($source));

        $source->on('data', function ($data) use ($source, $destination) {
            $feedMore = $destination->write($data);
            if (false === $feedMore) {
                $source->pause();
            }
        });

        $destination->on('drain', function () use ($source) {
            $source->resume();
        });

        $end = isset($options['end']) ? $options['end'] : true;

        if ($end && $source !== $destination) {
            $source->on('end', function () use ($destination) {
                $destination->end();
            });
        }

        return $destination;
    }
138047
public function generate($target, $options)
    {
        if ($options['source']) {
            $this->sourcePath = $options['source'];
        }

        $messages = $this->getMessages();
        $this->prepareTarget($target);

        if ($options['no-lib']) {
            $template = $this->file->get(__DIR__.'/Templates/messages.js');
        } else if ($options['json']) {
            $template = $this->file->get(__DIR__.'/Templates/messages.json');
        } else {
            $template = $this->file->get(__DIR__.'/Templates/langjs_with_messages.js');
            $langjs = $this->file->get(__DIR__.'/../../../../lib/lang.min.js');
            $template = str_replace('\'{ langjs }\';', $langjs, $template);
        }

        $template = str_replace('\'{ messages }\'', json_encode($messages), $template);

        if ($options['compress']) {
            $template = Minifier::minify($template);
        }

        return $this->file->put($target, $template);
    }