Binay data and createObjectURL

by some

HTML

<p>Firefox 10 example of createObjectURL with binary data using MozBlobBuilder</p>

JavaScript

// This code is for Firefox 10, and are using the now obsolete MozBlobBuilder.
var str="",
    idx, len,
    buf, view, blobbuild, blob, url,
    elem;
// create a test string
for (var idx = 0; idx < 256; ++idx) {
  str += String.fromCharCode(idx);
}

// create a buffer
buf = new ArrayBuffer(str.length);

// create a view as 8 bit unsigned integers of the buffer
view = new Uint8Array(buf);

// convert string to buffer
for (idx = 0, len = str.length; idx < len; ++idx) {
  view[idx] = str.charCodeAt(idx);
}

// create a blobbuilder, Mozilla style
blobbuild = new MozBlobBuilder();
blobbuild.append(buf); // append the buffer data
// Get the blob, and set the content type to application/octet-stream
blob = blobbuild.getBlob('application/octet-stream');

// Create an url
url = URL.createObjectURL(blob);

// Create and append an a-element to the documents body
elem = document.createElement('a');
elem.href = url;
elem.textContent = 'Downdload';
document.body.appendChild(elem);