久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在電子應(yīng)用程序中將文件從 blob 寫入磁盤

Write file to disk from blob in electron application(在電子應(yīng)用程序中將文件從 blob 寫入磁盤)
本文介紹了在電子應(yīng)用程序中將文件從 blob 寫入磁盤的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在創(chuàng)建一個 Electron 應(yīng)用程序,在其中我正在從網(wǎng)絡(luò)攝像頭和桌面記錄數(shù)據(jù),在記錄會話結(jié)束時,我想將數(shù)據(jù)保存到后臺的文件中.我不知道如何將數(shù)據(jù)從 blob 直接寫入文件.有什么建議?以下是我當(dāng)前對 MediaRecord Stop 事件的處理.

I am creating an Electron Application in which I am recording data from webcam and desktop, at the end of the recording session, I want to save the data to a file in the background. I do not know how to write the data from a blob to a file directly. Any suggestions? Below is my current handling for MediaRecord Stop event.

this.mediaRecorder.onstop = (e) => {                                      
       var blob = new Blob(this.chunks,                                      
                           { 'type' : 'video/mp4; codecs=H.264' });                                                       
       var fs = require('fs');                                               
       var fr = new FileReader();                                            
       var data = null;                                                      
       fr.onload = () => {                                                   
           data = fr.result;                                                 
           fs.writeFile("test.mp4", data, err => {                           
               if(err) {                                                     
                   return console.log(err);                                  
               }                                                             
               console.log("The file was saved!");                           
           });                                                               
       };                                                                    
       fr.readAsArrayBuffer(blob);                                           
   }                          

推薦答案

您可以使用 FileReaderBuffer 來完成.

You can do it using FileReader and Buffer.

在渲染器進程中,將事件發(fā)送到主進程以將文件與緩沖區(qū)一起保存:

In the renderer process, send the event to the main process to save the file with the buffer:

function saveBlob(blob) {
    let reader = new FileReader()
    reader.onload = function() {
        if (reader.readyState == 2) {
            var buffer = new Buffer(reader.result)
            ipcRenderer.send(SAVE_FILE, fileName, buffer)
            console.log(`Saving ${JSON.stringify({ fileName, size: blob.size })}`)
        }
    }
    reader.readAsArrayBuffer(blob)
}

取回確認(rèn):

ipcRenderer.on(SAVED_FILE, (event, path) => {
    console.log("Saved file " + path)
})

(SAVE_FILE 和 SAVED_FILE 是包含事件名稱的靜態(tài)字符串)

(SAVE_FILE and SAVED_FILE are static strings containing event name)

在主進程中:

ipcMain.on(SAVE_FILE, (event, path, buffer) => {
    outputFile(path, buffer, err => {
        if (err) {
            event.sender.send(ERROR, err.message)
        } else {
            event.sender.send(SAVED_FILE, path)
        }
    })
})

outputFile 來自 'fs-extra'

outputFile is from 'fs-extra'

首選在主進程中處理節(jié)點操作.請參閱 Electron 安全建議.

Handling node operations in main process is preferred. See Electron Security suggestions.

如果你不想使用主進程,你可以使用 'electron-remote' 創(chuàng)建后臺進程來寫入文件.此外,您可以在后臺進程中調(diào)用 ffmpeg 將文件壓縮/編碼為不同的格式.

If you do want to not use main process, you can use 'electron-remote' to create background processes to write the file. Additionally, you can invoke ffmpeg in the background process to compress/encode the file into different format.

這篇關(guān)于在電子應(yīng)用程序中將文件從 blob 寫入磁盤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創(chuàng)建子窗口時如何修復(fù) BrowserWindow 不是構(gòu)造函數(shù)錯誤) - IT屋-程序員軟件開發(fā)技術(shù)
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應(yīng)用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執(zhí)行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內(nèi)使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應(yīng)用程序中訪問相機/網(wǎng)絡(luò)攝像頭?)
主站蜘蛛池模板: 一区二区三区欧美在线观看 | 北条麻妃一区二区三区在线视频 | 91.xxx.高清在线 | 欧美日韩国产精品一区二区 | 欧美精产国品一二三区 | 狠狠视频| 久久日韩精品一区二区三区 | 国产999精品久久久 日本视频一区二区三区 | 免费看色 | 91视频正在播放 | 91在线一区二区三区 | 日韩一区不卡 | 久久婷婷国产麻豆91 | 日日操av | 久久专区| 欧美综合一区二区 | 99久久免费观看 | 久久国产日韩欧美 | 中文字幕在线观看www | 99久久久国产精品 | 国产精品永久免费视频 | 精品欧美视频 | 中文在线一区二区 | 一区二区三区中文字幕 | 高清国产一区二区 | 黑人巨大精品欧美一区二区免费 | 国产精品久久久久久吹潮 | 精品一区久久 | 一级黄色片一级黄色片 | 中文字幕高清视频 | 欧美精品一区二区三区在线 | 成人免费在线观看 | 国产精品不卡一区 | 国产精品一区久久久 | 国产女人与拘做视频免费 | 亚洲成人一级 | 欧美大片在线观看 | 欧美精品久久久久久久久久 | 91精品国产欧美一区二区 | 韩国主播午夜大尺度福利 | 精品在线看 |