paleolimbot commented on code in PR #12323: URL: https://github.com/apache/arrow/pull/12323#discussion_r848533304
########## r/R/io.R: ########## @@ -244,32 +245,59 @@ make_readable_file <- function(file, mmap = TRUE, compression = NULL, filesystem } if (is.string(file)) { if (is_url(file)) { - fs_and_path <- FileSystem$from_uri(file) - filesystem <- fs_and_path$fs - file <- fs_and_path$path + file <- tryCatch({ + fs_and_path <- FileSystem$from_uri(file) + filesystem <- fs_and_path$fs + fs_and_path$path + }, error = function(e) { + MakeRConnectionInputStream(url(file, open = "rb")) + }) } + if (is.null(compression)) { # Infer compression from the file path compression <- detect_compression(file) } + if (!is.null(filesystem)) { file <- filesystem$OpenInputFile(file) - } else if (isTRUE(mmap)) { + } else if (is.string(file) && isTRUE(mmap)) { file <- mmap_open(file) - } else { + } else if (is.string(file)) { file <- ReadableFile$create(file) } + if (!identical(compression, "uncompressed")) { file <- CompressedInputStream$create(file, compression) } } else if (inherits(file, c("raw", "Buffer"))) { file <- BufferReader$create(file) + } else if (inherits(file, "connection")) { + if (!isOpen(file)) { + open(file, "rb") + } + + # isSeekable() is not sufficient to check for seekability + # because we rely on seek(whence = "end") to get the size + # of the stream and a gzfile() is "seekable". Review Comment: I clarified this comment to be more relevant to its surrounding since. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org