Skip to content

Instantly share code, notes, and snippets.

@zeeshanlakhani
Created December 13, 2012 15:35
Show Gist options
  • Save zeeshanlakhani/4277199 to your computer and use it in GitHub Desktop.
Save zeeshanlakhani/4277199 to your computer and use it in GitHub Desktop.
/**
* 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