Allow another extension for asar archives


#1

I wish to be able to use a different file extension for asar archives.
I want to make my application a default application for opening certain type of files that are in fact asar archives but have some custom extension. My application shows some images and plays some audio files from archive and if archive has ‘asar’ extension then it is possible to construct url to those files inside archive, but if I change extension of archive then those urls are not recognized as valid.

I have looked in source code of lib/common/asar.js and found that it would require to change just one function splitPath. However this function is private and defined as const inside lib/common/asar.js. Maybe it can be changed so that it tries also some other file extension which can be given through environment variables or maybe dynamically changed through something like addArchiveExtension(ext)?

Is it possible to unpack electron.asar after installation and replace common/asar.js with patched version?
Vitalije


#2

Just have noticed that resources/electron.asar archive doesn’t contain common/asar.js file.


#3

I’d like this as well. We are currently trying to do the same thing. I want to package a collection of files into a single package and considered using an asar. I would really like to be able to use my own extension though. Are there any plans for something like this?


#4

Also… I wonder if it would be worth it to mod the splitPath function to add the necessary extension we want and then just build electron from source. We would also be stuck with compiling custom versions of electron but… could potentially get it to work. The package.json includes a build script that executes a python script that, just guessing, would build from source.


#5

Wanted to follow up one more time…

I went ahead and am proceeding forward with using the asar extension for now. I wanted to mention though that you will run into one more issue if you do the same. When you open an asar, the process will lock the asar file. This will prevent you from writing to it, overwriting it, deleting it, renaming it, etc. You won’t be able to do anything with the file until you reload the UI or restart the app.

To get around this, I made a Loading window that I open at application startup as hidden. When I want to open something, it will show that window and tell that child window to load any relevant data then close that window. I then listen to the close event on the window and when its closed, set a 1 s timer to open back up (hidden again).

Doing it this way will allow you to keep the loading and such encapsulated within that window (which is always good). By opening it initially and just leaving it hidden, it makes it where it comes up immediately when called instead of taking a second to load the view. That process for that child window will then have the asar locked. By closing the window though, that process is then destroyed then freeing the lock on the asar. Then it will auto launch itself again in the background so that it comes up immediately again the next time its invoked.