Created
August 1, 2018 20:21
-
-
Save VandeurenGlenn/b447ea030115cc185c23206d73d2f442 to your computer and use it in GitHub Desktop.
Buffer to ArrayBuffer
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
const {readFile} = require('fs'); | |
readFile('path/to/some/file', (error, buffer) => { | |
const arrayBuffer = new ArrayBuffer(buffer.length) | |
const bufferView = new Uint8Array(arrayBuffer); | |
for (var i=0, length=buffer.length; i < length; i++) { | |
bufferView[i] = buffer[i]; | |
} | |
console.log(buffer, arrayBuffer); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment