Skip to content

Instantly share code, notes, and snippets.

@coclav
Last active March 18, 2024 11:58
Show Gist options
  • Save coclav/4fd17efc9efa2c0517b2 to your computer and use it in GitHub Desktop.
Save coclav/4fd17efc9efa2c0517b2 to your computer and use it in GitHub Desktop.
Copy file out of ASAR archive for Electron app
var fs = require("fs");
var app = require("remote").require("app");
var fsj = require("fs-jetpack");
// example usage : copyFileOutsideOfElectronAsar( "myFolderInsideTheAsarFile", app.getPath("temp") + "com.bla.bla"
var copyFileOutsideOfElectronAsar = function(sourceInAsarArchive, destOutsideAsarArchive) {
if ( fs.existsSync( app.getAppPath() + "/" + sourceInAsarArchive ) ) {
// file will be copied
if ( fs.statSync( app.getAppPath() + "/" + sourceInAsarArchive ).isFile() ) {
fsj.file( destOutsideAsarArchive , fs.readFileSync( app.getAppPath() + "/" + sourceInAsarArchive ) );
}
// dir is browsed
else if ( fs.statSync( app.getAppPath() + "/" + sourceInAsarArchive ).isDirectory() ) {
fs.readdirSync( app.getAppPath() + "/" + sourceInAsarArchive ).forEach(function(fileOrFolderName) {
copyFileOutsideOfElectronAsar( sourceInAsarArchive + "/" + fileOrFolderName, destOutsideAsarArchive + "/" + fileOrFolderName );
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment