Electron intercept file:/// protocol to read inside zip files


I would like to read inside zip archives with Electron as if they were folders, like so /myfolder/myarchive.zip/picture.jpg. To do this I’m thinking about intercepting the file protocol

protocol.interceptFileProtocol('file', (request, callback) => {
    if (insideZipArchive) {
        //respond with zip file contents
    } else {

  }, (error) => {
    if (error) console.error('Failed to register protocol')

How do I invoke the default behavior? Also doing an AJAX request inside the interceptor and serving files like this callback({data: new Buffer(xhr.responseText)})does not seem to work.


You’ll want to look at something like Node-7z to extract or read the content.


Extracting zip files is not a problem. The problem is intercepting the protocol.


A year too late.
Recently, I do something to restore default file behaviour as follows
May not be fool-proof , just a gist

protocol.interceptFileProtocol(‘file’, (request, callback) => {
}, (error) => {
if (error) {
console.error(‘Failed to intercept file protocol’)


It looks like this could be solved with service workers, as shown here: