Skip to content

Instantly share code, notes, and snippets.

@kamituel
Created January 26, 2015 13:13
Show Gist options
  • Save kamituel/0aaf13c6f329c559476c to your computer and use it in GitHub Desktop.
Save kamituel/0aaf13c6f329c559476c to your computer and use it in GitHub Desktop.
Read file from app package without extracting to the filesystem
Cu.import("resource://gre/modules/FileUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
"resource://gre/modules/NetUtil.jsm");
let app = DOMApplicationRegistry.getAppByManifestURL(manifestURL);
if (!app) {
// handle
}
let appDir = FileUtils.getDir("coreAppsDir", ["webapps", app.id], false);
let appPackage = appDir.clone();
appPackage.append("application.zip");
let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
.createInstance(Ci.nsIZipReader);
zipReader.open(appPackage);
debug('has file: ' + zipReader.hasEntry("dev_cert.pem"));
let devCertStream = zipReader.getInputStream("dev_cert.pem");
let devCert = NetUtil.readInputStreamToString(devCertStream, devCertStream.available());
devCertStream.close();
debug("Dev cert: " + devCert);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment