resp_stream_raw {httr2}R Documentation

Read a streaming body a chunk at a time

Description

Use resp_stream_is_complete() to determine if there is further data waiting on the stream.

Usage

resp_stream_raw(resp, kb = 32)

resp_stream_lines(resp, lines = 1, max_size = Inf, warn = TRUE)

resp_stream_sse(resp, max_size = Inf)

resp_stream_aws(resp, max_size = Inf)

## S3 method for class 'httr2_response'
close(con, ...)

resp_stream_is_complete(resp)

Arguments

resp, con

A streaming response created by req_perform_connection().

kb

How many kilobytes (1024 bytes) of data to read.

lines

The maximum number of lines to return at once.

max_size

The maximum number of bytes to buffer; once this number of bytes has been exceeded without a line/event boundary, an error is thrown.

warn

Like readLines(): warn if the connection ends without a final EOL.

...

Not used; included for compatibility with generic.

Value

resp_stream_sse() and resp_stream_aws() will return NULL to signal that the end of the stream has been reached or, if in nonblocking mode, that no event is currently available.

Examples

req <- request(example_url()) |>
  req_template("GET /stream/:n", n = 5)

con <- req |> req_perform_connection()
while (!resp_stream_is_complete(con)) {
  lines <- con |> resp_stream_lines(2)
  cat(length(lines), " lines received\n", sep = "")
}
close(con)

# You can also see what's happening by setting verbosity
con <- req |> req_perform_connection(verbosity = 2)
while (!resp_stream_is_complete(con)) {
  lines <- con |> resp_stream_lines(2)
}
close(con)

[Package httr2 version 1.1.2 Index]