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

ZipFile is not released after unzip with OneZip #4

Closed
florianperrot44 opened this issue Feb 20, 2020 · 6 comments
Closed

ZipFile is not released after unzip with OneZip #4

florianperrot44 opened this issue Feb 20, 2020 · 6 comments
Labels

Comments

@florianperrot44
Copy link

florianperrot44 commented Feb 20, 2020

Here is my code :

var extract = onezip.extract(path.join(downloadFolder,entry.filename), path.join(downloadFolder,fileSansExt(entry.filename)));


					extract.on('progress', (percent) => {
						entry.win.webContents.send('unzip-progress', entry, percent);
					});

					extract.on('error', (error) => {
						entry.progress = "ERROR";
						log.error("unzip-ko "+error)
						entry.win.webContents.send('unzip-ko', entry, i18n.t("errors.unzipFailed"));
					});

					extract.on('end', () => {
						// extraction is complete. make sure to handle the err
						log.info('UNZIP end');
						entry.progress = "UNZIPED";
						entry.win.webContents.send('unzip-ok', entry);
						// DELETE THE ZIP FILE
						fs.unlinkSync(path.join(downloadFolder,entry.filename));
						controleFiles(entry);
					});

The unlink do nothing because, OneZip doesn't release the ZipFile.
Maybe you should set AutoClose in yauzl call.
Thanks.

@coderaiser
Copy link
Owner

What error do you have? Could you please simplify example and make it runnable :)?

@florianperrot44
Copy link
Author

florianperrot44 commented Feb 21, 2020

I want to delete the zip file after uncompress it.
The problem is the zip file isn't deleted after the unzip.

Here is a more intuitive code :

var fs = require('fs')

function test() {
  var extract = onezip.extract("myzip.zip", "folder");

  extract.on('end', () => {
	console.info('UNZIP end');
	// DELETE THE ZIP FILE
	fs.unlinkSync("myzip.zip");
	try {
          if (fs.existsSync("myzip.zip")) {
               //file exists
               console.info("Problem : the file is'nt deleted !!")
          }
       } catch(err) {
         console.error(err)
       }
});
}

@coderaiser
Copy link
Owner

I can't reproduce this with:

const fs = require('fs');
const onezip = require('onezip');

const extract = onezip.extract('./1.zip', '.');

extract.on('end', () => {
    console.info('UNZIP end');
    // DELETE THE ZIP FILE
    fs.unlinkSync('./1.zip');
    try {
        if (fs.existsSync('./1.zip')) {
            //file exists
            console.info('Problem : the file is\'nt deleted !!');
        }
    } catch(err) {}
});

I see only:

$ node 1
UNZIP end

Doesn't matter one file in archive or a couple.

@florianperrot44
Copy link
Author

Ok, maybe it depends on the system (specially for fs library).
The programm is executed under Windows 10 and inside Electron (latest).
Please, check it with this configuration.

Moreover, i resolved the problem with a fork of OneZip.
I've changed this line (232) in onezip.js :
const autoClose = true;

Can you change that for a future release ?

Thanks!

@coderaiser
Copy link
Owner

Unfortunately I can’t check this, but I think it worth fixing. Could you please send PR for this?

@coderaiser
Copy link
Owner

Fixed with #5, landed in landed in v4.2.1 🎉.
Is it works for you :)?

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

No branches or pull requests

2 participants