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

resulting archive missing file #4

Open
garretwilson opened this issue Sep 9, 2018 · 5 comments
Open

resulting archive missing file #4

garretwilson opened this issue Sep 9, 2018 · 5 comments

Comments

@garretwilson
Copy link

garretwilson commented Sep 9, 2018

This is the strangest thing: I'm zipping up a dist directory using npm, and jszip is skipping a file. I'm using Windows 10 Professional 64-bit.

The npm script in my package.json is simple:

"scripts" {
  "package": "jszip -o foobar.zip dist"
}

The files are inside dist/css. There are 27 files. It always skips one of them, guise-skeleton.min.css. Sometimes it skips two of them. I can see no rhyme or reason for this.

You can test this using the repository commit globalmentor/guise-skeleton@a5ad853 .

  1. Run npm install.
  2. Run npm run clean.
  3. Run npm run build.
  4. Look at the zip file generated in dist/. On my machine it is missing the file dist/css/guise-skeleton.min.css.

(If you want to simplify the build, simply change the "package" script to the one above and run npm run package after you've performed the build at least once.)

Why would jszip be ignoring files in the source directory?

@garretwilson
Copy link
Author

There are three similarly-named files in the source directory:

  • guise-skeleton.css
  • guise-skeleton.min.css
  • guise-skeleton.min.css.map

Most of the time it will skip guise-skeleton.min.css, although once or twice I've seen it include all 27 files.

If I delete guise-skeleton.min.css.map, then most of the time it will include guise-skeleton.min.css.

This is very weird and unpredictable.

@garretwilson
Copy link
Author

I wound up switching to cross-zip-cli. This also solved issue #3 for me.

@nylen
Copy link

nylen commented Oct 21, 2018

Same issue here. I'm switching to https://github.com/ffflorian/jszip-cli instead.

nylen added a commit to ClassicPress/nightly-builder that referenced this issue Oct 21, 2018
The previous choice had a really nasty bug...

Le0Michine/jszip-cli#4
@kenlyon
Copy link

kenlyon commented Nov 26, 2018

I think I've found the cause of the problem:

function readFiles(files, fileCallback, completeCallback) {
    files.forEach((file, i) => {
        var fileInfo = path.parse(file);
        fs.readFile(file, (err, data) => {
            if (!err) {
                fileCallback(fileInfo, data);
                if (i === files.length - 1) {
                    // *** The last few files may still be in progress at this point. ***
                    completeCallback();
                }
            } else {
                console.log("filed to read file", err);
            }
        });
    });
}

In my case, I found it was consistently the last or the last two files that were skipped. The order that the files are processed can vary, so it's not always the same file.

I believe the heart of the problem is that the check of i is checking how many files have started processing, not how many have finished. For example, if it starts processing the last file before the second last file has finished, then after the second last file finishes, it will see that i satisfies the terminating condition, and finalize the archive - before the final file has actually been added.

Since it looks like nobody's home here, I too shall be looking for a different solution.

@glukki
Copy link

glukki commented Mar 8, 2020

Same issue. Switched to folder-zip-sync

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

No branches or pull requests

4 participants