Skip to content

Commit

Permalink
Minor bugfix to handle unsorted ranges in the multipart requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Nov 7, 2024
1 parent 7ce81e0 commit 7c3c6f4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions R/downloadDatabaseRanges.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ downloadMultipartRanges <- function(url, start, end) {

req <- request(url)
o <- order(start)
ranges <- paste(sprintf("%s-%s", start[o], end[o] - 1L), collapse=", ") # byte ranges are closed intervals, not half-open.
start <- start[o]
end <- end[o]
ranges <- paste(sprintf("%s-%s", start, end - 1L), collapse=", ") # byte ranges are closed intervals, not half-open.
req <- req_headers(req, Range=paste0("bytes=", ranges))
resp <- req_perform(req)

if (length(start) == 1L) {
content <- resp_body_string(resp)
output[keep] <- substr(content, 1L, end - start)
output[keep[o]] <- substr(content, 1L, end - start)
return(output)
}

Expand All @@ -82,7 +84,7 @@ downloadMultipartRanges <- function(url, start, end) {
parsed <- parse_multipart_response(resp_body_string(resp), boundary)
chosen <- findInterval(start, parsed$start)
offset <- parsed$start
output[keep] <- substr(parsed$content[chosen], start - offset + 1L, end - offset)
output[keep[o]] <- substr(parsed$content[chosen], start - offset + 1L, end - offset)
output
}

Expand Down

0 comments on commit 7c3c6f4

Please sign in to comment.