Skip to content

Commit

Permalink
Use httr2 to download assets to avoid timeout and give a progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke committed Nov 30, 2023
1 parent 5561116 commit be13a30
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ Imports:
archive,
brio,
fs,
httr2 (>= 1.0.0),
jsonlite,
progress,
rappdirs,
rlang,
tools
Suggests:
plumber,
httr,
spelling,
testthat (>= 3.0.0)
Config/Needs/website: tidyverse/tidytemplate
Expand Down
18 changes: 10 additions & 8 deletions R/assets.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ assets_download <- function(
version = assets_version(),
...,
# Note that this is the cache directory, which is the parent of the assets
# directory. The tarball will have the assets directory as the top-level subdir.
# directory. The tarball will have the assets directory as the top-level
# subdir.
dir = assets_cache_dir(),
url = assets_bundle_url(version)) {
tmp_targz <- tempfile(paste0("shinylive-", gsub(".", "_", version, fixed = TRUE), "-"), fileext = ".tar.gz")
tmp_targz <- tempfile(
paste0("shinylive-", gsub(".", "_", version, fixed = TRUE), "-"),
fileext = ".tar.gz"
)

on.exit(
{
Expand All @@ -36,12 +40,10 @@ assets_download <- function(
)

message("Downloading shinylive assets v", version, "...")

# temporarily increase download timeout for ?utils::download.file guidelines
opts <- options(timeout = 250 * 60 * 2) # expect minimum 0.5 MB/s
on.exit(options(opts))

utils::download.file(url, destfile = tmp_targz, method = "auto")
req <- httr2::request(url)
req <- httr2::req_progress(req)
httr2::req_perform(req, path = tmp_targz)
message("") # Newline after progress bar

message("Unzipping to ", dir, "/")
fs::dir_create(dir)
Expand Down

0 comments on commit be13a30

Please sign in to comment.