public function setDownloadDir($dir) {
        // if no download dir is given, return
        if (is_null($dir)) {
            return $this;
        }
        
        // if the download directory is not a valid directory, throw an exception
        if (!is_dir($dir)) {
            throw new \Th\FileDownloader\Exceptions\DownloadException(\Th\FileDownloader::INVALID_DOWNLOAD_DIR);
        }
        
        // set the download directory
        $this->downloadDir = $dir;
        
        // done, return the instance of this, to make chaining possible
        return $this;
    }