node-unzipper
node-unzipper copied to clipboard
Extracting all of the file from a folder
I have a root folder in my zip file. I'm looking to extract all of the files in it, however in the destination folder this root folder should not appear.
Example: myFile.zip -> rootFolder - files
if I extract it to c:\temp, I do get c:\temp\rootFolder\files What I am looking for is to end up with c:\temp\files
Is there an elegant way to achieve this with the unzipper?
Not currently with the Extract method as it simply appends the full path of the file to the target directory.
You can however do this manually with either unzipper.Parse() and on each entry remove the part of the path you want to ignore and just use the first example in the readme (using fstream.Writer if you want sub-directories automatically created)
Leaving this issue open as this is a good feature request (PRs welcome)
You can take a hint from tar which has an option for to strip count leading path elements on extract:
--strip-components count
(x mode only) Remove the specified number of leading path elements.
Pathnames with fewer elements will be silently skipped. Note that
the pathname is edited after checking inclusion/exclusion patterns
but before security checks.
can i implement this feature or its already done
Was really hoping this would have complete parity with tar so I could make them completely interchangeable in my code depending on filetype. Would a PR for this be considered?
@josh-hemphill absolutely, as long as backward compatible