| 1 |
tricky_filename <- "\u00C0\u00CB\u00D0" |
| 2 |
|
| 3 |
# https://github.com/jeroen/curl/issues/182 |
| 4 |
test_that("curl_download() and curl_fetch_disk() can write to a non-ASCII path", { |
| 5 |
## chosen to be non-ASCII but |
| 6 |
## [1] representable in Windows-1252 and |
| 7 |
## [2] not any of the few differences between Windows-1252 and ISO-8859-1 |
| 8 |
## a-grave + e-diaeresis + Eth |
| 9 |
|
| 10 |
tmpdir <- tempfile() |
| 11 |
dir.create(tmpdir) |
| 12 |
on.exit(unlink(tmpdir, recursive = TRUE)) |
| 13 |
|
| 14 |
res <- curl_fetch_disk(httpbin("stream/10"), file.path(tmpdir, tricky_filename)) |
| 15 |
expect_true(file.exists(res$content)) |
| 16 |
unlink(list.files(tmpdir, full.names = TRUE)) |
| 17 |
|
| 18 |
res <- curl_download(httpbin("stream/10"), file.path(tmpdir, tricky_filename)) |
| 19 |
expect_true(file.exists(res)) |
| 20 |
}) |
| 21 |
|
| 22 |
test_that("curl_download() does not store failed downloads", { |
| 23 |
skip_if_not(grepl('UTF-8', Sys.getlocale())) |
| 24 |
dest1 <- tempfile(pattern = tricky_filename) |
| 25 |
curl_download(httpbin("get"), destfile = dest1) |
| 26 |
expect_true(file.exists(dest1)) |
| 27 |
unlink(dest1) |
| 28 |
|
| 29 |
dest2 <- tempfile() |
| 30 |
expect_error(curl_download(httpbin("status/404"), destfile = dest2)) |
| 31 |
expect_true(!file.exists(dest2)) |
| 32 |
}) |