Created
May 29, 2023 17:06
-
-
Save eliocamp/d9a9c0ccd42ea81fda4f47ce135af075 to your computer and use it in GitHub Desktop.
Monitor a download in progress and print a progress bar with speed and eta.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
total <- 116653684*1024 # change your total dir size here | |
folder_size <- function() { | |
system('du -s "[folder]"', intern = TRUE) %>% # change your dest folder here | |
strsplit(split = "\t", fixed = TRUE) %>% | |
.[[1]] %>% | |
.[1] %>% | |
as.numeric() | |
} | |
dt <- 5 | |
speed <- NA | |
size_before <- 0 | |
size_now <- 0 | |
pb <- progress::progress_bar$new(total = total, format = "[:bar]:spin :size (:percent) - :speed - :est", clear = FALSE) | |
while (size_now < total) { | |
Sys.sleep(dt) | |
size_now <- folder_size()*1024 | |
speed <- (size_now - size_before)/dt | |
est <- (total - size_now)/speed | |
est <- prettyunits::vague_dt(format = "short", as.difftime(est, units = "secs")) | |
speed <- paste0(scales::label_bytes()(speed), "/s") | |
pb$update(ratio = size_now/total, tokens = list(size = scales::label_bytes()(size*1024), | |
speed = speed, est = est)) | |
size_before <- size_now | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment