Skip to content

Commit

Permalink
Add createSubFolders option, default to true
Browse files Browse the repository at this point in the history
The zip files generated by gulp-zip do not actually contain "real"
folders (that is, folders with the `D` attribute and `store` method).
Opening a zip with a GUI decompression utility shows folders, but
they're really "virtual" folders that are just defined by the path of
the files in the zip.  Extracting the zips creates the actual folder
structure, but a decompression utility looking specifically for folders
won't find anything, as the `D` attribute is not present.

There's a pull request pending for JSZip to add an option to
automatically create "real" sub-folders when using the `.file` method
(Stuk/jszip#157).  This commit is in
anticipation of the pull request being accepted, so that gulp-zip can
take advantage of the new functionality in JSZip.  Including this option
in calls to JSZip before the option exists won't cause any errors, so
it's safe to preemptively add this to gulp-zip.  Currently, the
`createSubFolders` option defaults to `true`, but can be set to false by
passing `createSubFolders: false` as an option to gulp-zip.
  • Loading branch information
isochronous committed Jul 21, 2014
1 parent 166d8ea commit 8cd74fd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -11,6 +11,9 @@ module.exports = function (filename, opts) {
}

opts = opts || {};
opts.createSubFolders = (typeof opts.createSubFolders === 'undefined')
? true
: opts.createSubFolders;

var firstFile;
var zip = new JSZip();
Expand All @@ -33,7 +36,8 @@ module.exports = function (filename, opts) {
var pathname = file.relative.replace(/\\/g, '/');

zip.file(pathname, file.contents, {
date: file.stat ? file.stat.mtime : new Date()
date: file.stat ? file.stat.mtime : new Date(),
createSubFolders: opts.createSubFolders
});

cb();
Expand Down

0 comments on commit 8cd74fd

Please sign in to comment.