Electron Intercept file:/// 读取内部 zip 文件的协议
Electron Intercept file:/// protocol to read inside zip files
我想用 Electron 阅读内部的 zip 档案,就好像它们是文件夹一样,就像这样 /myfolder/myarchive.zip/picture.jpg
。为此,我正在考虑拦截文件协议
protocol.interceptFileProtocol('file', (request, callback) => {
if (insideZipArchive) {
//respond with zip file contents
} else {
//defaultBehavior
}
}, (error) => {
if (error) console.error('Failed to register protocol')
})
如何调用默认行为?同样在拦截器中执行 AJAX 请求并像这样 callback({data: new Buffer(xhr.responseText)})
提供文件似乎不起作用。
看起来这可以通过 service worker 解决,如下所示:
我想用 Electron 阅读内部的 zip 档案,就好像它们是文件夹一样,就像这样 /myfolder/myarchive.zip/picture.jpg
。为此,我正在考虑拦截文件协议
protocol.interceptFileProtocol('file', (request, callback) => {
if (insideZipArchive) {
//respond with zip file contents
} else {
//defaultBehavior
}
}, (error) => {
if (error) console.error('Failed to register protocol')
})
如何调用默认行为?同样在拦截器中执行 AJAX 请求并像这样 callback({data: new Buffer(xhr.responseText)})
提供文件似乎不起作用。
看起来这可以通过 service worker 解决,如下所示: