-
-
Save 1j01/2ee0cb5b44e770abcdb8fda92db64783 to your computer and use it in GitHub Desktop.
Electron blob to buffer, I made this to use with the nativeImage class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function blob_to_buffer(blob, callback) { | |
const file_reader = new FileReader() | |
file_reader.addEventListener("loadend", event => { | |
if (file_reader.error) { | |
callback(file_reader.error) | |
} else { | |
callback(null, new Buffer(file_reader.result)) | |
} | |
}, false) | |
// Read the blob as a typed array. | |
file_reader.readAsArrayBuffer(blob) | |
// ⚠ Always test your error handling! | |
// You can use this to do so! | |
// file_reader.abort() | |
// (When there's not an easy way to cause something to actually fail, | |
// you can at least test sending an error callback, btw) | |
return file_reader | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment