Skip to content

Commit

Permalink
Step 20.24: Add blobToArrayBuffer helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Kisiela authored and DAB0mB committed Dec 14, 2016
1 parent f01bc63 commit 3aac6e3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions imports/api/images/helpers.js
Expand Up @@ -29,3 +29,26 @@ export function dataURLToBlob(dataURL) {

return new Blob([uInt8Array], {type: contentType});
}

/**
* Converts Blob object to ArrayBuffer
*
* @param {Blob} blob Source file
* @param {Function} callback Success callback with converted object as a first argument
* @param {Function} errorCallback Error callback with error as a first argument
*/
export function blobToArrayBuffer(blob, callback, errorCallback) {
const reader = new FileReader();

reader.onload = (e) => {
callback(e.target.result);
};

reader.onerror = (e) => {
if (errorCallback) {
errorCallback(e);
}
};

reader.readAsArrayBuffer(blob);
}

0 comments on commit 3aac6e3

Please sign in to comment.