electron 使用asarstatFile判断文件是否存在一个asar里面
使用asar.statFile可以判断文件是否存在于asar包中。
示例代码:
const { statFile } = require('electron').remote.require('asar');
const path = require('path');
const asarPath = path.join(__dirname, 'app.asar');
const filePath = 'path/to/file';
try {
statFile(asarPath, filePath);
console.log(`${filePath} exists in ${asarPath}`);
} catch (err) {
console.log(`${filePath} does not exist in ${asarPath}`);
}
其中,asarPath为asar包的路径,filePath为要判断的文件路径。
如果文件存在,则不会抛出异常,输出${filePath} exists in ${asarPath};如果文件不存在,则会抛出异常,输出${filePath} does not exist in ${asarPath}
原文地址: https://www.cveoy.top/t/topic/eF4x 著作权归作者所有。请勿转载和采集!