Last active
November 5, 2019 20:46
-
-
Save trevorfoskett/7bdff5ec339976a6f89738ded97e04e3 to your computer and use it in GitHub Desktop.
Convert the base-64 encoded blob generated on the server into an array buffer for encryption.
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
/* | |
* Handles client-side conversion of document | |
* data from server to a format we can use for encryption. | |
* Called in both download & email workflows. | |
* | |
* @return {arrayBuffer} Array Buffer of the document content. | |
*/ | |
async function convertPDFData() { | |
// Gets document content; converts | |
// document content back into a usable | |
// PDF-type blob. | |
var blobB64 = await genPDF(); | |
var binary = atob(blobB64.replace(/\s/g, '')); | |
var len = binary.length; | |
var buffer = new ArrayBuffer(len); | |
var view = new Uint8Array(buffer); | |
for (var i =0; i < len; i++) { | |
view[i] = binary.charCodeAt(i); | |
} | |
var blob = new Blob([view], {type: "application/pdf"}); | |
// Generates an array buffer from the blob. | |
// Will be used as source data for encryption. | |
var arrayBuffer = null; | |
arrayBuffer = await new Response(blob).arrayBuffer(); | |
return arrayBuffer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment