Skip to content

Commit 153e575

Browse files
committed
Implemented binary file download.
Signed-off-by: ubi de feo <[email protected]>
1 parent 4e139e6 commit 153e575

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

backend/ipc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ module.exports = function registerIPCHandlers(win, ipcMain, app) {
4343

4444
ipcMain.handle('save-file', (event, filePath, content) => {
4545
console.log('ipcMain', 'save-file', filePath, content)
46-
fs.writeFileSync(filePath, content, 'utf8')
46+
const data = Buffer.from(content);
47+
fs.writeFileSync(filePath, data)
4748
return true
4849
})
4950

preload.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ const Serial = {
5353
const output = await board.fs_cat(file)
5454
return output || ''
5555
},
56+
loadFileBytes: async (file) => {
57+
const output = await board.fs_cat_bytes(file)
58+
return output || ''
59+
},
5660
removeFile: async (file) => {
5761
return board.fs_rm(file)
5862
},
@@ -63,7 +67,7 @@ const Serial = {
6367
return board.fs_put(src, dest, dataConsumer)
6468
},
6569
downloadFile: async (src, dest) => {
66-
let contents = await Serial.loadFile(src)
70+
let contents = await Serial.loadFileBytes(src)
6771
return ipcRenderer.invoke('save-file', dest, contents)
6872
},
6973
renameFile: async (oldName, newName) => {
@@ -123,6 +127,7 @@ const Disk = {
123127
return ipcRenderer.invoke('remove-file', filePath)
124128
},
125129
saveFileContent: async (filePath, content) => {
130+
console.log('saveFileContent', filePath, content)
126131
return ipcRenderer.invoke('save-file', filePath, content)
127132
},
128133
renameFile: async (oldName, newName) => {

0 commit comments

Comments
 (0)