gdown icon indicating copy to clipboard operation
gdown copied to clipboard

Add support to an user defined progress bar inside download function.

Open jcfaracco opened this issue 2 years ago • 2 comments

This commit just introduces a new argument to the download function: bar. The argument let the person who is developing code define his own progress bar using whatever he wants to. It also requires the pattern of passing the current size of the file and the total size.

An external function should be defined like

class MyBar:
    def __init__(self, total):
        self._total = total
        self.n = 0.0

    def update(self, cur_chunk_size):
        self.n += cur_chunk_size / self._total
        print(f"{self.n} %")

And then used as:

mybar = MyBar(total=total)
gdown.download(id=id, bar=mybar.update)

Signed-off-by: Julio Faracco [email protected]

jcfaracco avatar Feb 11 '23 19:02 jcfaracco