B2G/gecko/security/manager/ssl/tests/unit/test_signed_apps.js
// and/or a set of new entries to be included.
and/or a set of new entries to be included.
and / or a set of new entries to be included .
function tamper(inFilePath, outFilePath, modifications, newEntries) {
  var writer = Cc["@mozilla.org/zipwriter;1"].createInstance(Ci.nsIZipWriter);
  writer.open(outFilePath, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
  try {
    var reader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(Ci.nsIZipReader);
    reader.open(inFilePath);
    try {
      var entries = reader.findEntries("");
      while (entries.hasMore()) {
        var entryName = entries.getNext();
        var inEntry = reader.getEntry(entryName);
        var entryInput = reader.getInputStream(entryName);
        try {
          var f = modifications[entryName];
          var outEntry, outEntryInput;
          if (f) {
            [outEntry, outEntryInput] = f(inEntry, entryInput);
            delete modifications[entryName];
          } else {
            [outEntry, outEntryInput] = [inEntry, entryInput];
          }
          if (outEntryInput) {
            try {
              writer.addEntryStream(entryName,
                                    outEntry.lastModifiedTime,
                                    outEntry.compression,
                                    outEntryInput,
                                    false);
            } finally {
              if (entryInput != outEntryInput)
                outEntryInput.close();
            }
          }
        } finally {
          entryInput.close();
        }
      }
    } finally {
      reader.close();
    }
    for(var name in modifications) {
      if (modifications.hasOwnProperty(name)) {
        throw "input file was missing expected entries: " + name;
      }
    }
    newEntries.forEach(function(newEntry) {
      var sis = Cc["@mozilla.org/io/string-input-stream;1"]
                  .createInstance(Ci.nsIStringInputStream);
      try {
        sis.setData(newEntry.content, newEntry.content.length);
        writer.addEntryStream(newEntry.name,
                              new Date(),
                              Ci.nsIZipWriter.COMPRESSION_BEST,
                              sis,
                              false);
      } finally {
        sis.close();
      }
    });
  } finally {
    writer.close();
  }
}
function tamper ( inFilePath , outFilePath , modifications , newEntries ) { var writer = Cc [ "@mozilla.org/zipwriter;1" ] . createInstance ( Ci . nsIZipWriter ) ; writer . open ( outFilePath , PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE ) ; try { var reader = Cc [ "@mozilla.org/libjar/zip-reader;1" ] . createInstance ( Ci . nsIZipReader ) ; reader . open ( inFilePath ) ; try { var entries = reader . findEntries ( "" ) ; while ( entries . hasMore ( ) ) { var entryName = entries . getNext ( ) ; var inEntry = reader . getEntry ( entryName ) ; var entryInput = reader . getInputStream ( entryName ) ; try { var f = modifications [ entryName ] ; var outEntry , outEntryInput ; if ( f ) { [ outEntry , outEntryInput ] = f ( inEntry , entryInput ) ; delete modifications [ entryName ] ; } else { [ outEntry , outEntryInput ] = [ inEntry , entryInput ] ; } if ( outEntryInput ) { try { writer . addEntryStream ( entryName , outEntry . lastModifiedTime , outEntry . compression , outEntryInput , false ) ; } finally { if ( entryInput != outEntryInput ) outEntryInput . close ( ) ; } } } finally { entryInput . close ( ) ; } } } finally { reader . close ( ) ; } for ( var name in modifications ) { if ( modifications . hasOwnProperty ( name ) ) { throw "input file was missing expected entries: " + name ; } } newEntries . forEach ( function ( newEntry ) { var sis = Cc [ "@mozilla.org/io/string-input-stream;1" ] . createInstance ( Ci . nsIStringInputStream ) ; try { sis . setData ( newEntry . content , newEntry . content . length ) ; writer . addEntryStream ( newEntry . name , new Date ( ) , Ci . nsIZipWriter . COMPRESSION_BEST , sis , false ) ; } finally { sis . close ( ) ; } } ) ; } finally { writer . close ( ) ; } }
and/or a set of new entries to be included.
and / or a set of new entries to be included .
// if f does not want the input entry to be copied to the output entry // at all (i.e. it wants it to be deleted), it will return null. // Any leftover modification means that we were expecting to modify an entry // in the input file that wasn't there. // Now, append any new entries to the end