archive
archive copied to clipboard
`archive_extract()` not working for files compress using `data.table::fwrite()`
Hi!
I started working with archive
but stumbled upon the following problem: When I compress a csv file into a *. csv.gz archive using data.table::fwrite()
and then want to extract the archive using archive_extract()
, I get an error (see the reprex).
When I compress the csv file via archive_write_files()
, the extraction works without problems. Here is the reprex:
# load packages
library(archive)
#> Warning: package 'archive' was built under R version 4.0.5
library(data.table)
#> Warning: package 'data.table' was built under R version 4.0.5
# prepare example files
data(mtcars)
# write csv
tf <- tempfile(fileext = ".csv")
fwrite(mtcars, tf)
# compress csv to csv.gz
tf_gz = paste0(tf, ".gz")
archive_write_files(
archive = tf_gz,
files = tf,
format = "zip",
filter = "gzip"
)
# extracting the archive works
archive_extract(tf_gz, tempdir())
# clean up
file.remove(c(tf, tf_gz))
#> [1] TRUE TRUE
# write archive via data.table
fwrite(mtcars, tf_gz)
# extracting the archive does not work
archive_extract(tf_gz, tempdir())
#> Error: archive_extract.cpp:166 archive_read_next_header(): Missing type keyword in mtree specification
Created on 2022-02-03 by the reprex package (v2.0.1)
Is archive
made to extract all kinds of (supported) archives without any prior knowledge about the archives? This is what I'm actually looking for.
Seems like it could be a libarchive bug: https://github.com/libarchive/libarchive/issues/507 Maybe we could work around it by telling libarchive the format explicitly.