twolfson / grunt-zip

Zip and unzip files via a grunt plugin
MIT License
87 stars 19 forks source link

corrupted zip files #7

Closed markusfalk closed 11 years ago

markusfalk commented 11 years ago

the zip files created by grunt-zip get damaged. I tried on WIN wich unzips content but all images are broken.

on OSX the whole zip files doesn't contain any files or folders which results in the following error:

'Error 2 - No such file or directory exists'

zip: { 'html.zip': ['build/**'] }, grunt.registerTask('production', ['concat', 'copy', 'uglify', 'cssmin', 'imagemin', 'zip', 'clean']);

"devDependencies": { "grunt": "~0.4.0", "grunt-contrib-concat": "~0.1.2rc6", "grunt-contrib-imagemin": "~0.1.2", "grunt-contrib-jshint": "~0.1.1rc6", "grunt-contrib-uglify": "~v0.1.1rc6", "grunt-zip": "~0.3.0", "grunt-contrib-copy": "~0.4.0", "grunt-contrib-cssmin": "~0.4.1", "grunt-contrib-clean": "~0.4.0" }

twolfson commented 11 years ago

Interesting... can you point me to the zip file you are testing against?

markusfalk commented 11 years ago

sorry I can't provide the zip file because it contains my clients data. I could only try to reproduce it on another project.

twolfson commented 11 years ago

Damn, that is a shame. I have a test against Twitter Bootstrap which acts as solid common ground. https://github.com/twolfson/grunt-zip/blob/master/test/test_files/nested.zip

Can you verify npm test passes for you?

Also, if you could try to pass on any information about how the archive was created (e.g. created by PHP or 7z) , it would be useful.

markusfalk commented 11 years ago

npm test runs without errors.

how can I find out about how the zip was created?

twolfson commented 11 years ago

Double damn =(

I was hoping you would know since it is your clients data. This library actually wraps another one, jszip.

As a result, I am much more lacking in the knowledge of the inner workings of zips.

However, if you can't provide me with anything to reproduce (or gather information from to reproduce), we are at an impass =/

markusfalk commented 11 years ago

:/ ... it is my clients data in the zip file. but that doesn't help me find out how it was generated. or does it? I tried on WIN and OSX. I assumed the process would be different. I would like to provide more information if you can tell me how to inspect the zip file. If I had sent it to you, how would you try to find out how it was created?

twolfson commented 11 years ago

Nope, sending it to me would not really assist too much.

Ah, something just clicked -- you are creating zips, not unzipping. What kind of files are you compressing (e.g. csv, png)?

Heading to bed, I will respond to your next message later =)

markusfalk commented 11 years ago

sorry. I should have made that clearer. updated the issue with my grunt specs.

yes I am creating a zip with the grunt plugin. Then I tried to unzip it with my OS and get the error.

The zip contains: png, ico, jpg, css, js, html in different folders.

twolfson commented 11 years ago

Cool, thanks!

My shot in the dark is going to be some directory issue. Maybe even empty files within directories. I will let you know what I find.

Let the testing begin!

twolfson commented 11 years ago

Good news! I have successfully confirmed corruption of images on Linux Mint. I will get to patching this right away.

Progress thus far is visible on the bug/corrupted.zip.files branch.

twolfson commented 11 years ago

Hey Markus, great news! I have caught the issue and am repairing it now.

I was not telling jszip what encoding to expect and as a result, it was encoding a binary string improperly. https://github.com/Stuk/jszip/blob/master/jszip.js#L177-L219

I will let you know when the patch is in.

twolfson commented 11 years ago

Alright, I have added tests (one for image, one for nested directories) and both are passing =)

The changes are available on grunt-zip@0.4.2. If you have already gone up to 0.4.0, an npm update should boost you up easily.

One last note, globstar, **, in the context of minimatch usually expects an argument after it. In your case, it would be a * since you want to zip files.

'html.zip': 'build/**' // without
'html.zip': 'build/**/*' // with

The reason is that ** will return all files and directories whereas **/* will return files only. More info can be found in the minimatch documentation.

markusfalk commented 11 years ago

You are the best. I will try when i get back to the Office

markusfalk commented 11 years ago

awesome :+1:

the only thing i didn't understand is the minimatch pattern. I copy all of my files into the folder 'build'. What would it look like if I wanted to include only 'build's contents into the zip? It now packs the folder in the zip as well.

twolfson commented 11 years ago

The build/ directory is a fact of life until #1 is patched.

As for the globstar topic I was trying to explain, I will approach via gist.

twolfson commented 11 years ago

Alright, all done via a fork of a previous gist. Here are the results with src/**, src/**/*, src/* patterns on the following file structure:

+  src/
+  src.js
+    nested/
+      nested.js

Results:

globstar only (**):            [ 'src', 'src/nested', 'src/nested/nested.js', 'src/src.js' ]
globstar with asterisk (**/*): [ 'src/nested', 'src/nested/nested.js', 'src/src.js' ]
asterisk only (*):             [ 'src/nested', 'src/src.js' ]
twolfson commented 11 years ago

Feel free to pull down the gist and try it yourself: https://gist.github.com/twolfson/5088637

It seems I got the **/* not quite right since you still get directories back. However, you will notice it is missing the original directory which I think is preferred =)

markusfalk commented 11 years ago

thank you very much for your help :+1: