Using the zip-conduit
library, I want to extract a single file (e.g. bar/foo.txt
) from the ZIP archive.
The example on hackage only shows how to extract all files at once. How can I extract only a single file or a list of files?
Note: This question was answered using Q&A-style and therefore intentionally doesn't show any research effort!
The official example applies
extractFiles
to the[FilePath]
as returned byfileNames
. You can simply apply it to a custom list of filenames:This code will create a folder
bar
in the current working directory and extract the filefoo.txt
into said folder. If any such file already exists, it will be overwritten.If you intend to extract to a custom filename (e.g. you want to extract
foo.txt
to your current working directory, not to thebar
folder), you need to use conduits as shown in this example:Instead of using
CB.sinkFile
you can use any other conduit sink.