Skip to content

Instantly share code, notes, and snippets.

@socheatsok78
Created January 8, 2025 09:58
Show Gist options
  • Save socheatsok78/d5df5c34cb3e05df2aca1193a1bebf20 to your computer and use it in GitHub Desktop.
Save socheatsok78/d5df5c34cb3e05df2aca1193a1bebf20 to your computer and use it in GitHub Desktop.
/**
* A backward-compatible for FileReader: readAsBinaryString() method
* @param arrayBuffer {ArrayBuffer}
* @see https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsBinaryString
*/
function readAsBinaryString (arrayBuffer) {
const binary = []
const arrayBufferView = new Uint8Array(arrayBuffer)
for (let i = 0; i < arrayBufferView.length; i++) {
binary.push(String.fromCharCode(arrayBufferView[i]))
}
return binary.join('')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment