Skip to content

Instantly share code, notes, and snippets.

@kamituel
Last active August 29, 2015 14:14
Show Gist options
  • Save kamituel/38ff7a926cdd96d69076 to your computer and use it in GitHub Desktop.
Save kamituel/38ff7a926cdd96d69076 to your computer and use it in GitHub Desktop.
Read file from app package with extracting to the filesystem first
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 extractedDevCert = appDir.clone();
extractedDevCert.append("dev_cert.pem");
zipReader.extract("dev_cert.pem", extractedDevCert);
let devCertChannel = NetUtil.newChannel(extractedDevCert);
devCertChannel.contentType = "text/plain";
NetUtil.asyncFetch(devCertChannel, function(aStream, aResult) {
if (!Components.isSuccessCode(aResult)) {
debug("Could not read file " + extractedDevCert.path);
return;
}
debug("File read!!");
let devCert = NetUtil.readInputStreamToString(aStream, aStream.available());
debug("Dev cert: " + devCert);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment