Reading jarred files with JSLib

Assuming jslib gets a fix for a perceived bustage in fileUtils.js soon, here’s some code I whipped up for grabbing files from chrome, either jarred or flat:

  const fUtils = new FileUtils();
var localPath = fUtils.chromeToPath(sourceURI);
var isJarRE = /^jar:(file:\/\/\/.*\.jar)!\/(.*)/.exec(localPath);
var fileAsString = "";
if (isJarRE) {
var jarPath = fUtils.urlToPath(isJarRE[1]);
var jarFile = new File(jarPath);
var jarContents = new Zip(jarPath);;
fileAsString = jarContents.readEntry(isJarRE[2]);
} else {
var fileObj = new File(localPath);"r");
fileAsString =;

This assumes you’ve loaded chrome://jslib/content/jslib.js and chrome://jslib/content/io/io.js already.

On a side note, I’ve finished the first step of the 34-step Verbosio smoketest. This code above was needed to make sure I did things right.