Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't call the unzipper.extract from callback of unzipper.on('list', cb) #60

Open
trosemann opened this issue Jan 29, 2018 · 1 comment

Comments

@trosemann
Copy link

trosemann commented Jan 29, 2018

I want to decompress my archive only if there is a certain file inside. So i call unzipper.list() and check the files in unzipper.on('list')

unzipper.on('list', (files) => { if(fileFound(files){ unzipper.extract({path: folderPath}); }) });

If I do it like that, I got the following error:
"fd must be a file descriptor"

If I just call unzipper.extract() from outside the 'list' event, it works fine.

@lfwells
Copy link

lfwells commented Nov 30, 2019

I had the same problem. Not sure why, but creating a new DecompressZip object inside the list event fixed it (maybe calling list breaks the internal state of the object?). Not ideal obviously, and a bandaid solution, but worth a shot to anyone else who comes across this. Sample code:

`var unzipper = new DecompressZip(filepath);

    //first check the existence of the required files
    unzipper.on('list', function(files)
    {
        console.log("zip files:", files);
        //files are there, lets unzip!
        if (files.indexOf("html/index.html") != -1)
        {
            var unzipper = new DecompressZip(filepath);
            unzipper.on("extract", function () 
            {
                //file unzipped, now to handle the folder
                if (handleZip(extractPath, res))
                {
                    //success!
                }
            });
            unzipper.extract({ path: extractPath });
        }
        else
        {
            //return error etc 
        }
    });

    unzipper.list(); `

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants