From 7c3c6f4c0c8d0b838691bd317184bd3423c362ae Mon Sep 17 00:00:00 2001 From: LTLA Date: Wed, 6 Nov 2024 16:55:27 -0800 Subject: [PATCH] Minor bugfix to handle unsorted ranges in the multipart requests. --- R/downloadDatabaseRanges.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R/downloadDatabaseRanges.R b/R/downloadDatabaseRanges.R index 522480a..9766210 100644 --- a/R/downloadDatabaseRanges.R +++ b/R/downloadDatabaseRanges.R @@ -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) } @@ -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 }