JuliaIO / Tar.jl

TAR files: create, list, extract them in pure Julia
MIT License
80 stars 19 forks source link

Type of `dir` argument for `Tar.extract` #179

Closed cgarling closed 2 months ago

cgarling commented 2 months ago

Given a directory that has been converted into a tar archive, say "archive.tar", it is often typical to extract this into a directory simply named "archive". The obvious way to achieve this programmatically, for example, when you want to extract a list of tar archives input_files, is to set the list of output directory names as output_list = map(x->split(x,".tar")[1], input_files). However, split returns output with types SubString{String}. While Tar.extract accepts dir::AbstractString, I receive a downstream error from Tar.extract_tarball which requires the output root directory to be a String, with signature extract_tarball(predicate::Function, tar::IO, root::String; kws...).

This can be solved if the user converts the SubString to a standard String before passing to Tar.extract. This is not terribly inconvenient, but I hit this snag in my first attempt to use this package and it confused me for a few minutes. Is there a technical reason why the type of root cannot be any AbstractString in Tar.extract_tarball? Or perhaps Tar.extract should convert dir to a standard String before passing it to Tar.extract_tarball?

Running Julia 1.10.3 with Tar 1.10.0.

StefanKarpinski commented 2 months ago

Can reproduce. This is definitely a bug.