提问人:Dominique Blanchemain 提问时间:11/11/2023 最后编辑:Dominique Blanchemain 更新时间:11/11/2023 访问量:58
电子:(js)blob wav到main.js,以便从renderer.js保存到磁盘
electron : (js) blob wav to main.js for save to disk from renderer.js
问:
我在preload.js:
const { contextBridge, ipcRenderer } = require('electron')
// Toutes les API Node.js sont disponibles dans le processus de préchargement.
// Il a la même sandbox qu'une extension Chrome.
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector)
if (element) element.innerText = text
}
for (const dependency of ['chrome', 'node', 'electron']) {
replaceText(`${dependency}-version`, process.versions[dependency])
}
})
contextBridge.exposeInMainWorld(
"api", {
send: (channel, data) => {
// whitelist channels
let validChannels = ["toMain"];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
receive: (channel, func) => {
let validChannels = ["fromMain",'fromparam'];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
},
contextmenu: (channel, data) => {
// whitelist channels
let validChannels = ["showmenu"];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel,'showmenu')
}
}
}
)
我创建了一个“audio/wav”哑剧类型的 blob 我在index.html中这样做::
window.api.send("toMain", "saveAudioObjet;"+(audioDirectory+"exports/"+tableObjet[obj].id+".wav")+";"+blob)
我在main.js有这个: (通过 ipcMain.on (“toMain” ...
function saveAudioObjet(dest,buf) {
fs.writeFile(dest,
Buffer.from(buf), function (err) {
if (err) throw err;
console.log('Saved!')
})
}
如何将此 blob 保存到磁盘(dest is filePath, buf the blob)?
答: 暂无答案
评论