Created
January 10, 2024 02:23
-
-
Save AshKyd/0b3eb5105b736e8935274d3e983445c1 to your computer and use it in GitHub Desktop.
This file contains 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 dataTransferItemToArrayBuffer(dataTransferItem){ | |
return new Promise((resolve, reject) => { | |
if(dataTransferItem.kind !== 'file') {return reject(new Error('DataTransferItem is not of kind "file"'));} | |
const file = dataTransferItem.getAsFile(); | |
var reader = new FileReader(); | |
reader.onload = function() { | |
var arrayBuffer = this.result, | |
array = new Uint8Array(arrayBuffer); | |
resolve(arrayBuffer); | |
} | |
reader.onerror = reject; | |
reader.readAsArrayBuffer(file); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment