Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add progress bars for blob fs #6

Open
1 task
jenhagg opened this issue Sep 16, 2021 · 1 comment
Open
1 task

Add progress bars for blob fs #6

jenhagg opened this issue Sep 16, 2021 · 1 comment
Assignees

Comments

@jenhagg
Copy link
Collaborator

jenhagg commented Sep 16, 2021

🚀

  • Is your feature request essential for your project?
    No, but it would be pretty nice.

Describe the workflow you want to enable

I want progress bars for upload/download.

Describe your proposed implementation

Write a custom download method instead of delegating to the base FS implementation. The download method allows for additional kwargs, one of which should be a callback, so that the exact progress bar implementation is left up to consumers.

Note: the BlobFile implementation first downloads the blob to a temp file before any read operations occur. We should consider providing some context to the user since the progress bar function below is delayed until the initial download is complete. Alternatively, the behavior could be optimized, but this might be difficult to do while preserving the file-like-object api.

Describe alternatives you've considered, if relevant

Not having progress bars.

Additional context

Refer to the similar customization done for the ssh fs

@jenhagg jenhagg changed the title Feature request Add progress bars for blob fs Sep 16, 2021
@jenhagg
Copy link
Collaborator Author

jenhagg commented Oct 13, 2021

Snippet to add progress bar to download operation. Could be provided as documentation and copy/paste as needed, or integrated into the package somehow. TBD which approach is best..

def download(bfs, path, dst_file):
    size = bfs.getinfo(path, namespaces=["details"]).size
    with bfs.openbin(path) as src_file:
        read = src_file.read
        write = dst_file.write
        with tqdm(
            unit="B",
            unit_scale=True,
            unit_divisor=1024,
            miniters=1,
            total=size,
        ) as pbar:
            for chunk in iter(lambda: read(4096) or None, None):
                write(chunk)
                pbar.update(len(chunk))


with open("hydro.csv", "wb") as f:
    download(bfs, "raw/usa_tamu/hydro_vJan2021.csv", f)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants