Skip to content

Instantly share code, notes, and snippets.

@coclav
Last active March 18, 2024 11:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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