bundle.core.downloader

Attributes

log

Classes

Downloader

Handles asynchronous downloading of files from a specified URL.

DownloaderTQDM

Extends Downloader with TQDM progress bar for visual feedback during download.

Module Contents

bundle.core.downloader.log
class bundle.core.downloader.Downloader(/, **data: Any)[source]

Bases: bundle.core.entity.Entity

Handles asynchronous downloading of files from a specified URL.

url

The URL to download the file from.

Type:

str

destination

The local file path to save the downloaded file. If None, data is stored in memory.

Type:

Path | None

chunk_size

The size of each chunk to download at a time.

Type:

int

buffer

A buffer to temporarily store the file’s content if no destination is specified.

Type:

bytearray

start(byte_size

int): Placeholder for initialization logic before downloading starts.

update(byte_count

int): Placeholder for update logic as chunks of data are downloaded.

end()[source]

Placeholder for cleanup logic after the download completes.

download() bool[source]

Asynchronously downloads a file from url to destination or to buffer.

url: str
destination: pathlib.Path | None = None
chunk_size: int = 4096
name: str = None
property buffer: bytearray

Expose the in-memory buffer for downstream consumers.

property error_message: str
start(byte_size: int)[source]

Initializes the download process. Placeholder for subclasses to implement.

update(byte_count: int)[source]

Updates the download progress. Placeholder for subclasses to implement.

end()[source]

Finalizes the download process. Placeholder for subclasses to implement.

async download() bool[source]

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.

Return type:

bool

class bundle.core.downloader.DownloaderTQDM(/, **data: Any)[source]

Bases: 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.

start(byte_size: int)[source]

Initializes the TQDM progress bar.

update(byte_count: int)[source]

Updates the TQDM progress bar with the number of bytes downloaded.

end()[source]

Closes the TQDM progress bar.