You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
can you please add a example on how to extract a specific folder ?
thanks in advance for your help
download('urltofile').pipe(unzipper.Parse()).on('entry', function (entry)
{
var fileName = entry.path;
var type = entry.type;
var size = entry.size;
if (type === 'Directory' && /src\/assets\/scss/i.test(fileName))
{
//extract this folder
}
else
{
entry.autodrain();
}
});
The text was updated successfully, but these errors were encountered:
Every entry has the full path of the filename in the entry.path. So you can pick your files with something like this:
varWriter=require('fstream').Writer;download('urltofile').pipe(unzipper.Parse()).on('entry',function(entry){// filename will be undefined if it doesn't match the regexvarfilename=/src\/assets\/scss\/(.*)/i.exec(entry.path);if(type!='Directory'&&filename){entry.pipe(writer({path: filename[1]}));}else{entry.autodrain();}});
If the incoming zip files are untrusted you also might want to protect against extracting files above the target directory by adding a check like this:
// to avoid zip slip (writing outside of the destination), we resolve// the target path, and make sure it's nested in the intended// destination, or not extract it otherwise.varextractPath=path.join(opts.path,entry.path);if(extractPath.indexOf(opts.path)!=0){entry.autodrain();return;}
Please reopen if this doesn't work or if you have any questions/comments!
hi
can you please add a example on how to extract a specific folder ?
thanks in advance for your help
The text was updated successfully, but these errors were encountered: