JMCrocs
JMCrocs

Reputation: 77

Extract LZIP (.lz)

I would like to extract a JSON file compressed with Lzip (.lz). I have tried with untar, unzip, and the archive library, sadly none of them work.

download.file(url = "https://parltrack.org/dumps/ep_votes.json.lz",
              destfile = "ep_votes.json.lz",
               mode = "wb")
archive("ep_votes.json.lz")
# Erreur : archive.cpp:37 archive_read_open1(): Unrecognized archive format

untar("ep_votes.json.lz", exdir = ".")
# tar.exe: Error opening archive: Can't initialize filter; unable to run program "lzip -d -q"
# Warning message:
# In untar("ep_votes.json.lz", exdir = ".") :
#   ‘tar.exe -xf "ep_votes.json.lz" -C "."’ returned error code 1

unzip("ep_votes.json.lz", exdir = ".")

# Warning message:
# In unzip("ep_votes.json.lz", exdir = ".") :
# erreur 1 lors de l'extraction d'un fichier zip

Here is the documentation about lzip: https://www.nongnu.org/lzip/lzip.html.

It works naturally with Winrar but I would like to do it in R directly.

Do you have an idea on how to fix those errors or is there another solution?

Upvotes: 1

Views: 2370

Answers (1)

JMCrocs
JMCrocs

Reputation: 77

Jim Hester gave the answer through his GitHub :

lzip is a compression format, not an archive format, e.g. it compresses only a single file, it does not store multiple files like a zip or tar archive would.

So you need to use archive::file_read() rather than archive().

e.g. data <- jsonlite::parse_json(archive::file_read("ep_votes.json.lz"), simplifyVector=FALSE)

source : https://github.com/r-lib/archive/issues/52

Upvotes: 2

Related Questions