Created
December 13, 2012 15:35
-
-
Save zeeshanlakhani/4277199 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
/** | |
* Creates an ArrayBuffer, converts the binary to a Uint8 Array, and | |
* places the buffer in a DataView, which is needed to create a Blob | |
**/ | |
_makeBlob: function(binary) { | |
var data = new ArrayBuffer(binary.length), | |
mimeString = "text/plain", | |
ui8a = new Uint8Array(data, 0), | |
dataView, | |
blob; | |
// & is a bit-wise operation | |
for (var i = 0; i < binary.length; i++) { | |
ui8a[i] = (binary.charCodeAt(i) & 0xff); | |
} | |
dataView = new DataView(data); | |
blob = new Blob([dataView], {type: mimeString}); | |
return blob; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment