6

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 {
        //defaultBehavior
    }

  }, (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.

user2939415
  • 864
  • 1
  • 11
  • 22
  • I ended up solving this problem by having a Node.js server extract and serve files from the ZIP archive. – user2939415 Mar 07 '17 at 22:11
  • Why do you need a server? Why can't you simply read the zip files from the renderer? – Tim Jan 15 '18 at 23:14
  • Because I was working with an existing code base, which used URLs to fetch files. Reading the zip archives from the renderer would have required rewriting a lot of code. – user2939415 Jan 17 '18 at 10:01

1 Answers1

0

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

How to intercept all http requests including form submits

user2939415
  • 864
  • 1
  • 11
  • 22