summaryrefslogtreecommitdiffstats
path: root/modules/libjar/zipwriter/test/unit/test_bug446708.js
blob: cff67d848aa095b6fba3ed67dfc9886dcde48d4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function run_test() {
  var testBundle = do_get_file("data/test_bug446708");

  RecursivelyZipDirectory(testBundle);
}

// Add |file| to the zip. |path| is the current path for the file.
function AddToZip(zipWriter, path, file) {
  var currentPath = path + file.leafName;

  if (file.isDirectory()) {
    currentPath += "/";
  }

  // THIS IS WHERE THE ERROR OCCURS, FOR THE FILE "st14-1.tiff" IN "test_bug446708"
  zipWriter.addEntryFile(
    currentPath,
    Ci.nsIZipWriter.COMPRESSION_DEFAULT,
    file,
    false
  );

  // if it's a dir, continue adding its contents recursively...
  if (file.isDirectory()) {
    var entries = file.QueryInterface(Ci.nsIFile).directoryEntries;
    while (entries.hasMoreElements()) {
      var entry = entries.nextFile;
      AddToZip(zipWriter, currentPath, entry);
    }
  }

  // ...otherwise, we're done
}

function RecursivelyZipDirectory(bundle) {
  zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
  AddToZip(zipW, "", bundle);
  zipW.close();
}