download an existing file using Writer
@param string $fileName
@param \SMB\Arrayto\Interfaces\Writable $writer
347015
public function downloadExistsFileUsingWriter($fileName, Writable $writer)
    {
        header("Content-Type: text/csv; charset={$this->getHeaderCharset()}");
        header("Content-Disposition: attachment; filename={$fileName}");

        $writer->write();
        readfile($writer->getFileName());
    }
611438
public function as_download( $filename = null ) 
	{
		if ( is_null( $filename ) ) 
		{
			$filename = 'file.'.CCStr::suffix( $this->header( 'Content-Type' ), '/' );
		}

		$this->header( 'Content-Description', 'File Transfer' );
		$this->header( 'Content-Disposition', 'attachment; filename='.$filename );
		$this->header( 'Content-Transfer-Encoding', 'binary' );
		$this->header( 'Expires', '0' );
		$this->header( 'Cache-Control', 'must-revalidate' );
		$this->header( 'Pragma', 'public' );
		$this->header( 'Content-Length', strlen( $this->body() ) );

		return $this;
	}
250248
public function download($filename, $alias = null)
    {
        $fileDowloader = new FileDownloader($this->headerBag);
        $fileDowloader->download($filename, $alias);

        // Terminate the script with success
        exit(1);
    }
1228281
public function save($filename, $class = 'File') {
    if(!empty($this->pdf->getError())) {
      throw new Exception('Could not create PDF: ' . $this->pdf->getError());
    } else {
      $filename = rtrim($class::create()->setName($filename), '.pdf') . '.pdf';
      $this->pdf->saveAs($this->folder . $filename);
      return $this->createFile($filename, $class);
    }
  }
1116629
private function appendFile(Writer $writer, PhingFile $f)
    {
        $in = $this->getFilteredReader(new FileReader($f));

        $text = '';
        while (-1 !== ($buffer = $in->read())) { // -1 indicates EOF
            $text .= $buffer;
        }
        if ($this->fixLastLine && ($text[strlen($text) - 1] !== "\n" || $text[strlen($text) - 1] !== "\r")) {
            $text .= $this->eolString;
        }

        $text = $this->appendHeader($text);
        $text = $this->appendFooter($text);
        $writer->write($text);
        if ($f instanceof PhingFile && $this->to instanceof PhingFile) {
            $this->log("Appending contents of " . $f->getPath() . " to " . $this->to->getPath());
        }
    }
306011
private function readFile($filename)
    {
        if (!file_exists($filename)) {
            throw new \Exception(sprintf('File not found: %s', $filename));
        }
        if (!is_readable($filename) || ($content = file_get_contents($filename)) === false) {
            throw new \Exception(sprintf('Failed to read file: %s', $filename));
        }

        return $content;
    }
1066630
def download(self, remote, writer):
        

        fd = self.open(remote)
        while True:
            chunk = self.read(fd)
            if chunk == b'':
                break
            writer.write(chunk)
        self.close(fd)
669353
public static function saveFile($input, $fileName)
    {
        $fh = fopen($fileName, 'w') or die('cant open file');
        fwrite($fh, $input);
        fclose($fh);
    }
652610
public function download(string $filename, array $params = [])
    {
        $path = $this->buildAttachmentsPath($filename);

        return $this->pureGet($path, $params, ['Accept' => '*/*'])->getBody();
    }
962686
public function write(WriterInterface $writer)
    {
        $this->writer = $writer;
        $this->error  = null;
        $writer->setDocument($this);
        $writer->begin();
        try {
            $this->addLog(sprintf('Start writing document "%s"', basename($this->filename)));
            $this->physicalModel->write($writer);
            $this->addLog('Done writing document');
        } catch (\Exception $e) {
            $this->error = $e;
            $this->addLog($e->getMessage(), LoggerInterface::ERROR);
        }
        $writer->end();

        return $this;
    }
225167
public function process($filename, $actualFileName)
    {
        // Check if the processing should be done
        if(!$this->shouldProcess($filename))
        {
            // No need to process the file, so bypass
            return $this->getFinalName($filename);
        }
        
        // Otherwise write the file and return the new file name
        return $this->write(Compiler::compile(file_get_contents($filename)), $actualFileName);
    }
1085389
public function save( $fileName )
	{
		$svg	= $this->encapsulate( $this->content );
		$doc	= new DOMDocument();
		$doc->preserveWhiteSpace = false; 
		$doc->formatOutput = true;
		$doc->loadXml( $svg );
		$svg	= $doc->saveXml();
		return FS_File_Writer::save( $fileName, $svg );
	}
314784
public function save(string $filename, bool $force_download = false)
    {
        return $this->getWriter()->save($filename, $force_download = false);
    }
359201
public function download($mediaId, $directory, $filename = '')
    {
        if (!is_dir($directory) || !is_writable($directory)) {
            throw new InvalidArgumentException("Directory does not exist or is not writable: '$directory'.");
        }
        $filename = $filename ?: $mediaId;
        $stream = $this->getStream($mediaId);
        $finfo = new finfo(FILEINFO_MIME);
        $mime = strstr($finfo->buffer($stream), ';', true);
        $extensions = FileHelper::getExtensionsByMimeType($mime);
        $filename .= '.' . array_pop($extensions);
        $filePath = $directory . '/' . $filename;
        file_put_contents($filePath, $stream);
        return $filePath;
    }
1227169
public function write( $fileName )
	{
		$lines	= array();
		if( $this->useSections )
		{
			foreach( $this->data as $section => $sectionPairs )
			{
				$lines[]	= "[".$section."]";
				foreach ( $sectionPairs as $key => $data )
				{
					$value		= $data['value'];
					$comment	= $data['comment'];
					$lines[]	= $this->buildLine( $key, $value, $comment);
				}
				$lines[]	= "";
			}
		}
		else
		{
			foreach( $this->data as $key => $data )
			{
				$value		= $data['value'];
				$comment	= $data['comment'];
				$lines[]	= $this->buildLine( $key, $value, $comment);
			}
			$lines[]	= "";
		}
		$file		= new FS_File_Writer( $fileName, 0664 );
		return $file->writeArray( $lines );
	}
890378
public function update($filename, $content)
    {
        if ($this->exists($filename) && $this->isFile($filename)) {
            return $this->create($filename, $content);
        }

        throw new FileNotFoundException('File not found in the path [ ' . $filename . ' ].');
    }
654826
protected function makeFile($filename, $content, $force)
    {
        if ($this->fileExists($filename, $force)) {
            throw new Exception('The destination file already exists. To override the existing file, pass "--force" option.');
        }

        if (!File::put($filename, $content)) {
            throw new Exception('Unexpected error occurred while trying to create the file. please try your request again.');
        }

        return $this;
    }