:py:mod:`tonic.download_utils`
==============================

.. py:module:: tonic.download_utils


Module Contents
---------------


Functions
~~~~~~~~~

.. autoapisummary::

   tonic.download_utils.calculate_md5
   tonic.download_utils.check_md5
   tonic.download_utils.check_integrity
   tonic.download_utils.download_url
   tonic.download_utils.extract_archive
   tonic.download_utils.download_and_extract_archive
   tonic.download_utils.iterable_to_str
   tonic.download_utils.list_files



Attributes
~~~~~~~~~~

.. autoapisummary::

   tonic.download_utils.USER_AGENT
   tonic.download_utils.T


.. py:data:: USER_AGENT
   :value: 'tonic'

   

.. py:function:: calculate_md5(fpath: str, chunk_size: int = 1024 * 1024) -> str


.. py:function:: check_md5(fpath: str, md5: str, **kwargs: Any) -> bool


.. py:function:: check_integrity(fpath: str, md5: Optional[str] = None) -> bool


.. py:function:: download_url(url: str, root: str, filename: Optional[str] = None, md5: Optional[str] = None, max_redirect_hops: int = 3) -> None

   Download a file from a url and place it in root.

   :param url: URL to download file from
   :type url: str
   :param root: Directory to place downloaded file in
   :type root: str
   :param filename: Name to save the file under. If None, use the basename of the URL
   :type filename: str, optional
   :param md5: MD5 checksum of the download. If None, do not check
   :type md5: str, optional
   :param max_redirect_hops: Maximum number of redirect hops allowed
   :type max_redirect_hops: int, optional


.. py:function:: extract_archive(from_path: str, to_path: Optional[str] = None, remove_finished: bool = False) -> str

   Extract an archive.

   The archive type and a possible compression is automatically detected from the file name. If the file is compressed
   but not an archive the call is dispatched to :func:`decompress`.

   :param from_path: Path to the file to be extracted.
   :type from_path: str
   :param to_path: Path to the directory the file will be extracted to. If omitted, the directory of the file is
                   used.
   :type to_path: str
   :param remove_finished: If ``True``, remove the file after the extraction.
   :type remove_finished: bool

   :returns: Path to the directory the file was extracted to.
   :rtype: (str)


.. py:function:: download_and_extract_archive(url: str, download_root: str, extract_root: Optional[str] = None, filename: Optional[str] = None, md5: Optional[str] = None, remove_finished: bool = False) -> None


.. py:function:: iterable_to_str(iterable: Iterable) -> str


.. py:function:: list_files(root: str, suffix: str, prefix: bool = False) -> List[str]

   List all files ending with a suffix at a given root
   :param root: Path to directory whose folders need to be listed
   :type root: str
   :param suffix: Suffix of the files to match, e.g. '.png' or ('.jpg', '.png').
                  It uses the Python "str.endswith" method and is passed directly
   :type suffix: str or tuple
   :param prefix: If true, prepends the path to each result, otherwise
                  only returns the name of the files found
   :type prefix: bool, optional


.. py:data:: T

   

