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
extractFilesto the[FilePath]as returned byfileNames. You can simply apply it to a custom list of filenames:This code will create a folder
barin the current working directory and extract the filefoo.txtinto 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.txtto your current working directory, not to thebarfolder), you need to use conduits as shown in this example:Instead of using
CB.sinkFileyou can use any other conduit sink.