Last active
August 29, 2015 14:14
-
-
Save kamituel/38ff7a926cdd96d69076 to your computer and use it in GitHub Desktop.
Read file from app package with extracting to the filesystem first
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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