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

Fix #425 #426

Merged
merged 7 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rio
Type: Package
Title: A Swiss-Army Knife for Data I/O
Version: 1.1.0
Version: 1.1.1
Authors@R: c(person("Jason", "Becker", role = "aut", email = "[email protected]"),
person("Chung-hong", "Chan", role = c("aut", "cre"), email = "[email protected]",
comment = c(ORCID = "0000-0002-6232-7530")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# rio 1.1.1

Bus fixes

* Fix #425 for archive formats, the file extension of the input file is determined by the compressed file (like prior rio 1.1.0)

# rio 1.1.0

* CRAN release
Expand Down
8 changes: 8 additions & 0 deletions R/compression.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,11 @@ parse_archive <- function(file, which, file_type, ...) {
}
NULL
}

.get_compressed_format <- function(cfile, file, file_type, format) {
if (file_type %in% c("gzip", "bzip2")) {
return(ifelse(isFALSE(missing(format)), tolower(format), get_info(find_compress(cfile)$file)$input))
}
## zip or tar formats, use the decompressed file path
return(ifelse(isFALSE(missing(format)), tolower(format), get_info(file)$input))
}
2 changes: 1 addition & 1 deletion R/import.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ import <- function(file, format, setclass = getOption("rio.import.class", "data.
cfile <- file
file <- f$file
which <- ifelse(missing(which), 1, which)
format <- ifelse(isFALSE(missing(format)), tolower(format), get_info(file)$input)
file <- parse_archive(cfile, which = which, file_type = f$compress)
format <- .get_compressed_format(cfile, file, f$compress, format)
## reset which if `file` is zip or tar. #412
which <- .reset_which(file_type = f$compress, which = which)
}
Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/test_compress.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,24 @@ test_that("tar export error for R < 4.0.3", {
expect_error(export(iris, iris_path), "^Exporting")
})
})

test_that("Wild zip and tar ref $425", {
skip_if(getRversion() <= "4.0")
##skip_on_os("windows")
withr::with_tempfile("test_files", fileext = c(".csv", ".zip"), code = {
filename <- test_files[1]
zip_file <- test_files[2]
write.csv(1, filename)
zip(zip_file, filename)
expect_error(rio::import(zip_file), NA)
})
for (tar_format in c("tar", "tar.gz", "tar.bz2")) {
withr::with_tempfile("test_files", fileext = c(".csv", paste0(".", tar_format)), code = {
filename <- test_files[1]
tar_file <- test_files[2]
write.csv(1, filename)
compress_out(tar_file, filename, type = tar_format)
expect_error(rio::import(tar_file), NA)
})
}
})
Loading