2

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?

1 Answer 1

2

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!
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.