added new api saveFileToDisk and renamed saveToDisk to saveStreamToDisk

This commit is contained in:
Abhinav-grd 2021-03-31 12:14:56 +05:30
parent 24f6d4026f
commit 396ec0fbbc

View file

@ -27,12 +27,16 @@ const checkExistsAndCreateCollectionDir = async (dirPath: string) => {
}
};
const saveToDisk = (path: string, fileStream: ReadableStream<any>) => {
const saveStreamToDisk = (path: string, fileStream: ReadableStream<any>) => {
const writeable = fs.createWriteStream(path);
const readable = responseToReadable(fileStream);
readable.pipe(writeable);
};
const saveFileToDisk = async (path: string, file: any) => {
await fs.writeFile(path, file);
};
const selectRootDirectory = async () => {
try {
return await ipcRenderer.sendSync('select-dir');
@ -76,7 +80,8 @@ const showOnTray = (item: any[]) => {
var windowObject: any = window;
windowObject['ElectronAPIs'] = {
checkExistsAndCreateCollectionDir,
saveToDisk,
saveStreamToDisk,
saveFileToDisk,
selectRootDirectory,
updateExportRecord,
getExportedFiles,