I spent some time this evening writing the code that adds a similar method to XHR of Google Chrome, but my implementation should theoretically work with any browser that implements the latest web standards. I did not spend much time testing the code, so it might have bugs in it. It probably is not the most efficient way either. I am just publishing it here in spirit of release early release often.
XMLHttpRequest.prototype.sendAsBinary = function(datastr) {
var bb = new BlobBuilder();
var data = new ArrayBuffer(1);
var ui8a = new Uint8Array(data, 0);
for (var i in datastr) {
if (datastr.hasOwnProperty(i)) {
var chr = datastr[i];
var charcode = chr.charCodeAt(0)
var lowbyte = (charcode & 0xff)
ui8a[0] = lowbyte;
bb.append(data);
}
}
var blob = bb.getBlob();
this.send(blob);
}
As I implied, my code is in no way optimal. Feel free to post improved versions as comments.
VastaaPoistaFor info on BlobBuilder see http://www.w3.org/TR/file-writer-api/#idl-def-BlobBuilder
VastaaPoista...and for info on ArrayBuffer see https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/doc/spec/TypedArray-spec.html
Here are the Mozilla pages defining the method:
VastaaPoistahttps://developer.mozilla.org/en/XMLHttpRequest#sendAsBinary()
https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Sending_binary_data
And this is the original bug report for Chrome
http://code.google.com/p/chromium/issues/detail?id=35705
It turns out Blogger does not support code in comments. I have moved development of the function to http://javascript0.org/wiki/Portable_sendAsBinary
VastaaPoista