def __unpack(self, package, wd, allow_unknown_filetype=True):
        """Unpack package and set source directory"""

        match_tar = re.search(r'(.*)(?:(?:\.tar)|(?:\.tar\.gz)|(?:\.txz)'
                              r'|(?:\.tgz)|(?:\.tar\.bz2)|(?:\.tar\.xz))$',
                              posixpath.basename(package))

        match_zip = re.search(r'(.*)(?:(?:\.zip))$',
                              posixpath.basename(package))

        if match_tar:
            # Set directory where to find source
            self.src_directory = posixpath.join(wd, match_tar.group(1))
            return hpccm.templates.tar().untar_step(
                posixpath.join(wd, posixpath.basename(package)), directory=wd)
        elif match_zip:
            self.src_directory = posixpath.join(wd, match_zip.group(1))
            return hpccm.templates.zipfile().unzip_step(
                posixpath.join(wd, posixpath.basename(package)), directory=wd)
        elif allow_unknown_filetype:
            # Unclear what the file type is.  For instance, this can
            # happen if a site uses a URL redirector and the shortened
            # URL does not include the file extension.  In most cases,
            # tar can figure it out.  However, note that the src
            # directory is set to None since there is no way to infer
            # what the directory structure might be inside the
            # archive.
            logging.warning('unrecognized package format')
            self.src_directory = None
            return hpccm.templates.tar().untar_step(
                posixpath.join(wd, posixpath.basename(package)), directory=wd)
        else:
            raise RuntimeError('unrecognized package format')
Unpack package and set source directory
hpccm/templates/downloader.py