creates an output stream for given target

@param   mixed  $target   target to create output stream for
@param   array  $options  list of options for the output stream
@return  \stubbles\streams\file\FileOutputStream
320860
public function createOutputStream($target, array $options = []): OutputStream
    {
        if (isset($options['createDirIfNotExists']) && true === $options['createDirIfNotExists']) {
            $dir = dirname($target);
            if (!file_exists($dir)) {
                $filemode = $options['dirPermissions'] ?? $this->fileMode;
                mkdir($dir, $filemode, true);
            }
        }

        $filemode = $options['filemode'] ?? 'wb';
        $delayed  = $options['delayed']  ?? false;
        return new FileOutputStream($target, $filemode, $delayed);
    }
692371
protected OutputStream createOutputStream (File target)
        throws IOException
    {
        JarOutputStream jout = new JarOutputStream(new FileOutputStream(target));
        jout.setLevel(Deflater.BEST_COMPRESSION);
        return jout;
    }
763652
public function createInputStream($source, array $options = []): InputStream
    {
        if (isset($options['filemode'])) {
            return new FileInputStream($source, $options['filemode']);
        }

        return new FileInputStream($source);
    }
654639
public function writeFile($filePath = null, array $options = [])
    {
        $filePath = empty($filePath)
            ? $this->filePath
            : $filePath;

        if ($this->count()) {
            return (new File())->write($filePath, json_encode($this->getArrayCopy(), JSON_PRETTY_PRINT));
        }
    }
1199313
function stream($filename, $options = null) {

    // Add page text
    $this->_add_page_text();

    if ( isset($options["compress"]) && $options["compress"] != 1 )
      $this->_pdf->set_value("compress", 0);
    else
      $this->_pdf->set_value("compress", 6);

    $this->_close();

    if ( self::$IN_MEMORY ) {
      $data = $this->_pdf->get_buffer();
      $size = strlen($data);

    } else
      $size = filesize($this->_file);


    $filename = str_replace(array("\n","'"),"", $filename);
    $attach = (isset($options["Attachment"]) && $options["Attachment"]) ? "attachment" : "inline";

    header("Cache-Control: private");
    header("Content-type: application/pdf");
    header("Content-Disposition: $attach; filename=\"$filename\"");

    //header("Content-length: " . $size);

    if ( self::$IN_MEMORY )
      echo $data;

    else {

      // Chunked readfile()
      $chunk = (1 << 21); // 2 MB
      $fh = fopen($this->_file, "rb");
      if ( !$fh )
        throw new DOMPDF_Exception("Unable to load temporary PDF file: " . $this->_file);

      while ( !feof($fh) )
        echo fread($fh,$chunk);
      fclose($fh);

      //debugpng
      if (DEBUGPNG) print '[pdflib stream unlink '.$this->_file.']';
      if (!DEBUGKEEPTEMP)

      unlink($this->_file);
      $this->_file = null;
      unset($this->_file);
    }

    flush();
  }
623785
public function output($target, $content)
    {
        foreach ($this->filters as $filter) {
            $content = $filter->output($target, $content);
        }
        return $content;
    }
890520
private function getStreamOutput(StreamOutput $output = null)
    {
        if ($output) {
            rewind($output->getStream());
            $this->consoleOutput[] = trim(stream_get_contents($output->getStream()));
            fclose($output->getStream());
        }

        return new StreamOutput(fopen('php://memory', 'w+', false), StreamOutput::VERBOSITY_VERBOSE);
    }
1276950
protected function merge($target, $source)
    {
        if ($source === null) {
            return $target;
        }

        return call_user_func($this->merge, $target, $source);
    }
957042
public function createImagesFromVideos($source, $target = 'step-%03d.jpg')
    {
        try {
            $this->serviceLocator->setShared('playgroundcore_phpvideotoolkit', false);

            $this->serviceLocator->get('playgroundcore_phpvideotoolkit')
            ->addPreInputCommand('-y')
            ->addCommand('-i', $source)
            ->setOutputPath($target)
            ->execute();
        } catch (FfmpegProcessOutputException $e) {
            throw new \PHPVideoToolkit\InvalidArgumentException('Error when merging videos');
        } catch (\PHPVideoToolkit\Exception $e) {
            throw new \PHPVideoToolkit\InvalidArgumentException('Error when merging videos');
        }

        return $target;
    }
1099052
public function getFormatOption($format, $options = [])
  {
    $format = isset($this->format[$format]) ?  $this->format[$format] : Format::create($format, $options);
    if (isset($options['output']) && empty($format->getOutput())) {
      $format->setOutput($options['output']);
    }
    return $format;
  }
1097431
public function copy($source, $target)
    {
        $it = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS);
        $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);

        if (!file_exists($target)) {
            mkdir($target, 0777, true);
        }

        foreach ($ri as $file) {
            $targetPath = $target . DIRECTORY_SEPARATOR . $ri->getSubPathName();
            if ($file->isDir()) {
                if (!file_exists($targetPath)) {
                    mkdir($targetPath);
                }
            } else {
                copy($file->getPathname(), $targetPath);
            }
        }
    }
234496
public function overlayOnMp4($source, $layer, $target)
    {
        if (!is_array($layer)) {
            $layer = array($layer);
        }
        $overlay = '';
        $this->serviceLocator->setShared('playgroundcore_phpvideotoolkit', false);
       
        $ffmpeg = $this->serviceLocator->get('playgroundcore_phpvideotoolkit')
            ->addPreInputCommand('-y')
            ->addCommand('-i', $source, true);

        foreach ($layer as $k => $l) {
            $ffmpeg->addCommand('-i', $l, true);
            $overlay .= 'overlay=format=rgb';
            if ($k<count($layer)-1) {
                $overlay .= ',';
            }
        }

        $ffmpeg->addCommand('-filter_complex', $overlay.'[out]')
            ->addCommand('-map', '[out]')
            ->addCommand('-vcodec', 'qtrle')
            ->setOutputPath($target)
            ->execute();

        return $target;
    }
24863
private static function create(string $target): OutputStream
    {
        $out      = new self(fopen($target, 'w'));
        $encoding = self::detectOutputEncoding();
        if ('UTF-8' !== $encoding) {
            $out = new EncodingOutputStream($out, $encoding . '//IGNORE');
        }

        return $out;
    }
599580
public function switchCommand($target = '')
    {
        if ($target === '' && $values = $this->arguments->getValues()) {
            $target = $values[0];
        }

        if ($target === '') {
            $target = $this->arguments->getOption('env');
        }

        $candidates = [];
        foreach ($this->_getEnvTypes() as $file) {
            if (strpos($file, $target) === 0) {
                $candidates[] = $file;
            }
        }

        if (count($candidates) !== 1) {
            return $this->console->error(['can not one file: :env', 'env' => implode(',', $candidates)]);
        }
        $target = $candidates[0];

        $glob = '@root/.env[._-]' . $target;
        $files = $this->filesystem->glob($glob);
        if ($files) {
            $file = $files[0];
            $this->filesystem->fileCopy($file, '@root/.env', true);
            if (file_exists($file . '.php')) {
                $this->filesystem->fileDelete($file . '.php');
            }
            $this->console->writeLn(['copy `:src` to `:dst` success.', 'src' => basename($file), 'dst' => '.env']);
            return 0;
        } else {
            return $this->console->error(['dotenv file `:file` is not exists', 'file' => $glob]);
        }
    }
310204
public function copy($target, $source)
    {
        $source_stream = $this->readStream($source);
        $result = $this->writeStream($target, $source_stream);

        fclose($source_stream);

        return $result;
    }
1352469
public function writeProcessingInstruction(string $target, string $data = ''): XmlStreamWriter
    {
        return $this->append(
                function(\DOMNode $parent) use ($target, $data)
                {
                    $parent->appendChild($this->doc->createProcessingInstruction(
                            $target,
                            $data
                    ));
                },
                'processing instruction'
        );
    }
860784
public function setTarget($target)
    {
        if (!file_exists(dirname($target))) {
            throw new Exception\InvalidArgumentException("The directory '$target' does not exist");
        }

        $target = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, (string) $target);
        $this->options['target'] = $target;
        return $this;
    }