newbiedev
newbiedev

Reputation: 3586

create blob from file path vue electron bulider

I'm using the fs module in my electron app to read file content from path

ipcMain.on('fileData', (event, data) => {
 data.forEach( (file) => { 
  const stream = fs.createReadStream(file)
  stream.on('data', (buffer) => {
    console.log(buffer)
  })
 })
})

I'm able to open the files but I get a buffer. what I want is to create blob from the files to do some process on them. How I can achive this in electron?

Upvotes: 2

Views: 551

Answers (1)

Codesmith
Codesmith

Reputation: 6752

If you're trying to create a Blob in the main process, i.e. the NodeJS environment, keep in mind that NodeJS has no support for Blobs.

If you're trying to create a Blob in the renderer process from a file, though, you can use a preloader or enable nodeIntegration. Then you can use something like the following:

const fs = require('fs');
const stream = fs.createReadStream(filepath);

var blob = new Blob([]); // empty blob

stream.on('data', (buffer) => {
    blob = new Blob([blob, buffer]); // concatenate buffer
});
stream.on('close', () => {
    // blob is ready!
});

Upvotes: 2

Related Questions