B2G/gecko/testing/mochitest/chrome-harness.js
/*
 * input:
 *  jar: a nsIJARURI object with the jarfile and jarentry (path in jar file)
 *
 * output;
 *  all files and subdirectories inside jarentry will be extracted to TmpD/mochikit.tmp
 *  we will return the location of /TmpD/mochikit.tmp* so you can reference the files locally
 */
a nsIJARURI object with the jarfile and jarentry (path in jar file)

output;
all files and subdirectories inside jarentry will be extracted to TmpD/mochikit.tmp
we will return the location of /TmpD/mochikit.tmp* so you can reference the files locally
a nsIJARURI object with the jarfile and jarentry ( path in jar file ) output ; all files and subdirectories inside jarentry will be extracted to TmpD / mochikit . tmp we will return the location of / TmpD / mochikit . tmp * so you can reference the files locally
function extractJarToTmp(jar) {
  var tmpdir = Components.classes["@mozilla.org/file/directory_service;1"]
                      .getService(Components.interfaces.nsIProperties)
                      .get("ProfD", Components.interfaces.nsILocalFile);
  tmpdir.append("mochikit.tmp");
  tmpdir.createUnique(Components.interfaces.nsIFile.DIRECTORY_TYPE, parseInt("0777", 8));
  var zReader = Components.classes["@mozilla.org/libjar/zip-reader;1"].
                  createInstance(Components.interfaces.nsIZipReader);
  var fileHandler = Components.classes["@mozilla.org/network/protocol;1?name=file"].
                    getService(Components.interfaces.nsIFileProtocolHandler);
  var fileName = fileHandler.getFileFromURLSpec(jar.JARFile.spec);
  zReader.open(fileName);
  var filepath = "";
  var parts = jar.JAREntry.split('/');
  for (var i =0; i < parts.length - 1; i++) {
    if (parts[i] != '') {
      filepath += parts[i] + '/';
    }
  }
  var dirs = zReader.findEntries(filepath + '*/');
  while (dirs.hasMore()) {
    var targetDir = buildRelativePath(dirs.getNext(), tmpdir, filepath);
    targetDir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, parseInt("0777", 8));
  }
  var files = zReader.findEntries(filepath + "*");
  while (files.hasMore()) {
    var fname = files.getNext();
    if (fname.substr(-1) != '/') {
      var targetFile = buildRelativePath(fname, tmpdir, filepath);
      zReader.extract(fname, targetFile);
    }
  }
  return tmpdir;
}
function extractJarToTmp ( jar ) { var tmpdir = Components . classes [ "@mozilla.org/file/directory_service;1" ] . getService ( Components . interfaces . nsIProperties ) . get ( "ProfD" , Components . interfaces . nsILocalFile ) ; tmpdir . append ( "mochikit.tmp" ) ; tmpdir . createUnique ( Components . interfaces . nsIFile . DIRECTORY_TYPE , parseInt ( "0777" , 8 ) ) ; var zReader = Components . classes [ "@mozilla.org/libjar/zip-reader;1" ] . createInstance ( Components . interfaces . nsIZipReader ) ; var fileHandler = Components . classes [ "@mozilla.org/network/protocol;1?name=file" ] . getService ( Components . interfaces . nsIFileProtocolHandler ) ; var fileName = fileHandler . getFileFromURLSpec ( jar . JARFile . spec ) ; zReader . open ( fileName ) ; var filepath = "" ; var parts = jar . JAREntry . split ( '/' ) ; for ( var i = 0 ; i < parts . length - 1 ; i ++ ) { if ( parts [ i ] != '' ) { filepath += parts [ i ] + '/' ; } } var dirs = zReader . findEntries ( filepath + '*/' ) ; while ( dirs . hasMore ( ) ) { var targetDir = buildRelativePath ( dirs . getNext ( ) , tmpdir , filepath ) ; targetDir . create ( Components . interfaces . nsIFile . DIRECTORY_TYPE , parseInt ( "0777" , 8 ) ) ; } var files = zReader . findEntries ( filepath + "*" ) ; while ( files . hasMore ( ) ) { var fname = files . getNext ( ) ; if ( fname . substr ( - 1 ) != '/' ) { var targetFile = buildRelativePath ( fname , tmpdir , filepath ) ; zReader . extract ( fname , targetFile ) ; } } return tmpdir ; }
input:
  jar: a nsIJARURI object with the jarfile and jarentry (path in jar file)
input : jar : a nsIJARURI object with the jarfile and jarentry ( path in jar file )
// parseInt is used because octal escape sequences cause deprecation warnings // in strict mode (which is turned on in debug builds) //filepath represents the path in the jar file without the filename /* Create dir structure first, no guarantee about ordering of directories and
   * files returned from findEntries.
   */ // parseInt is used because octal escape sequences cause deprecation warnings // in strict mode (which is turned on in debug builds) //now do the files