bundle.core.downloader ====================== .. py:module:: bundle.core.downloader Attributes ---------- .. autoapisummary:: bundle.core.downloader.log Classes ------- .. autoapisummary:: bundle.core.downloader.Downloader bundle.core.downloader.DownloaderTQDM Module Contents --------------- .. py:data:: log .. py:class:: Downloader(/, **data: Any) Bases: :py:obj:`bundle.core.entity.Entity` Handles asynchronous downloading of files from a specified URL. .. attribute:: url The URL to download the file from. :type: str .. attribute:: destination The local file path to save the downloaded file. If None, data is stored in memory. :type: Path | None .. attribute:: chunk_size The size of each chunk to download at a time. :type: int .. attribute:: buffer A buffer to temporarily store the file's content if no destination is specified. :type: bytearray .. method:: start(byte_size int): Placeholder for initialization logic before downloading starts. .. method:: update(byte_count int): Placeholder for update logic as chunks of data are downloaded. .. method:: end() Placeholder for cleanup logic after the download completes. .. method:: download() -> bool Asynchronously downloads a file from `url` to `destination` or to `buffer`. .. py:attribute:: url :type: str .. py:attribute:: destination :type: pathlib.Path | None :value: None .. py:attribute:: chunk_size :type: int :value: 4096 .. py:attribute:: name :type: str :value: None .. py:property:: buffer :type: bytearray Expose the in-memory buffer for downstream consumers. .. py:property:: error_message :type: str .. py:method:: start(byte_size: int) Initializes the download process. Placeholder for subclasses to implement. .. py:method:: update(byte_count: int) Updates the download progress. Placeholder for subclasses to implement. .. py:method:: end() Finalizes the download process. Placeholder for subclasses to implement. .. py:method:: download() -> bool :async: Asynchronously downloads a file from the specified URL. The file is either saved to the given destination path or stored in an in-memory buffer. Utilizes aiohttp for asynchronous HTTP requests and aiofiles for async file I/O operations. :returns: True if the download was successful, False otherwise. :rtype: bool .. py:class:: DownloaderTQDM(/, **data: Any) Bases: :py:obj:`Downloader` Extends Downloader with TQDM progress bar for visual feedback during download. Overrides the start, update, and end methods of Downloader to integrate a TQDM progress bar that updates with each downloaded chunk. .. py:method:: start(byte_size: int) Initializes the TQDM progress bar. .. py:method:: update(byte_count: int) Updates the TQDM progress bar with the number of bytes downloaded. .. py:method:: end() Closes the TQDM progress bar.