public function download($localfile = null, $remotefile = null)
{
if (isset($localfile) && is_dir($localfile) && isset($this->output->filename)) {
$localfile = realpath($localfile) . DIRECTORY_SEPARATOR . (isset($remotefile) ? $remotefile : $this->output->filename);
} elseif (!isset($localfile) && isset($this->output->filename)) {
$localfile = isset($remotefile) ? $remotefile : $this->output->filename;
}
if (!isset($localfile) || is_dir($localfile)) {
throw new Exceptions\InvalidParameterException("localfile parameter is not set correctly");
}
return $this->downloadStream(fopen($localfile, 'w'), $remotefile);
}