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

Handle errors properly when req_perform_connection(mode="text") #533

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions R/req-perform-stream.R
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,24 @@
}

read_con <- function(con, buffer = 32 * 1024) {
bytes <- raw()
repeat {
new <- readBin(con, "raw", n = buffer)
if (length(new) == 0) break
bytes <- c(bytes, new)
if (identical(summary(con)$text, "text")) {
# The connection is in text mode; readBin will error. So we must read it as

Check warning on line 333 in R/req-perform-stream.R

View check run for this annotation

Codecov / codecov/patch

R/req-perform-stream.R#L332-L333

Added lines #L332 - L333 were not covered by tests
# characters and then convert to bytes.
chars <- character()
repeat {
new <- readChar(con, nchars = buffer)
if (length(new) == 0) break
chars <- c(chars, new)
}
# TODO: Seems wrong that there's no mention of encodings here??
bytes <- charToRaw(chars)
} else {
bytes <- raw()

Check warning on line 344 in R/req-perform-stream.R

View check run for this annotation

Codecov / codecov/patch

R/req-perform-stream.R#L344

Added line #L344 was not covered by tests
repeat {
new <- readBin(con, "raw", n = buffer)
if (length(new) == 0) break
bytes <- c(bytes, new)
}

Check warning on line 349 in R/req-perform-stream.R

View check run for this annotation

Codecov / codecov/patch

R/req-perform-stream.R#L347-L349

Added lines #L347 - L349 were not covered by tests
}
if (length(bytes) == 0) {
NULL
Expand Down
Loading