Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix : the folders wasn't marked as folder.

Also, add some unit tests.
  • Loading branch information...
commit 821d25e2d601e1099b15e7dbc82273450fe3c1e7 1 parent c4da116
@dduponchel dduponchel authored
Showing with 43 additions and 1 deletion.
  1. +1 −1  jszip.js
  2. +42 −0 test/index.html
View
2  jszip.js
@@ -487,7 +487,7 @@ JSZip.prototype = (function () {
// internal file attributes TODO
"\x00\x00" +
// external file attributes
- (this.files[name].dir===true?"\x10\x00\x00\x00":"\x00\x00\x00\x00")+
+ (this.files[name].options.dir===true?"\x10\x00\x00\x00":"\x00\x00\x00\x00")+
// relative offset of local header
decToHex(fileOffset, 4) +
// file name
View
42 test/index.html
@@ -432,7 +432,30 @@
var actual = JSZipBase64.decode(content);
ok(similar(actual, expected, 18) , "Generated ZIP matches reference ZIP");
+ });
+
+ testZipFile("Delete folder with a final /", "ref/text.zip", function(expected) {
+ var zip = new JSZip();
+ zip.folder("remove").file("Remove.txt", "This folder and file should be deleted\n");
+ zip.file("Hello.txt", "Hello World\n");
+ zip.remove("remove/");
+ var content = zip.generate();
+
+ var actual = JSZipBase64.decode(content);
+
+ ok(similar(actual, expected, 18) , "Generated ZIP matches reference ZIP");
+ });
+
+ testZipFile("Delete unknown path", "ref/text.zip", function(expected) {
+ var zip = new JSZip();
+ zip.file("Hello.txt", "Hello World\n");
+ zip.remove("unknown_file");
+ zip.remove("unknown_folder/Hello.txt");
+ var content = zip.generate();
+
+ var actual = JSZipBase64.decode(content);
+ ok(similar(actual, expected, 18) , "Generated ZIP matches reference ZIP");
});
testZipFile("Delete nested folders", "ref/text.zip", function(expected) {
@@ -740,6 +763,16 @@
ok(similar(actual, expected, 18) , "Generated ZIP matches reference ZIP");
});
+
+ test("unknown compression throws an exception", function () {
+ var zip = new JSZip();
+ try {
+ zip.generate({compression:'MAYBE'});
+ ok(false, "no exception");
+ } catch (e) {
+ ok(true, "an exception were thrown");
+ }
+ });
// }}} More advanced
module("Load file, not supported features"); // {{{
@@ -889,6 +922,15 @@
equal(zip.file("€15.txt").asText(), "€15\n", "the utf8 content was correctly read (with file().asText).");
equal(zip.files["€15.txt"].asText(), "€15\n", "the utf8 content was correctly read (with files[].astext).");
});
+
+ test("A folder stays a folder", function () {
+ var zip = new JSZip();
+ zip.folder("folder/");
+ ok(zip.files['folder/'].options.dir, "the folder is marked as a folder");
+ var reloaded = new JSZip(zip.generate({base64:false}));
+ ok(reloaded.files['folder/'].options.dir, "the folder is marked as a folder");
+ });
+
// }}} Load file
module("Load complex files"); // {{{

0 comments on commit 821d25e

Please sign in to comment.
Something went wrong with that request. Please try again.