Generates a closure that writes binary (raw) data to a file.
file_writer(path)
path | file name or path on disk |
---|
Function with signature writer(data = raw(), close = FALSE)
The writer function automatically opens the file on the first write and closes when
it goes out of scope, or explicitly by setting close = TRUE
. This can be used
for the data
callback in multi_add()
or curl_fetch_multi()
.
# Doesn't open yet tmp <- tempfile() writer <- file_writer(tmp) # Now it opens writer(charToRaw("Hello!\n"))#> [1] 7#> [1] 13#> [1] 10#> [1] "Hello!" "How are you?" "All done!"