var array =newInt8Array([17,-45.3]);try{var jpeg =newBlob([array],{type :"image/jpeg"});}catch(e){// TypeError old chrome and FF
window.BlobBuilder= window.BlobBuilder||
window.WebKitBlobBuilder||
window.MozBlobBuilder||
window.MSBlobBuilder;if(e.name =='TypeError'&& window.BlobBuilder){var bb =newBlobBuilder();
bb.append([array.buffer]);var jpeg = bb.getBlob("image/jpeg");}elseif(e.name =="InvalidStateError"){// InvalidStateError (tested on FF13 WinXP)var jpeg =newBlob([array.buffer],{type :"image/jpeg"});}else{// We're screwed, blob constructor unsupported entirely }}
var aFileParts =["<a id=\"a\"><b id=\"b\">hey!<\/b><\/a>"];var oMyBlob =newBlob(aFileParts,{"type":"text\/xml"}); // the blob
等同于:
var oBuilder =newBlobBuilder();var aFileParts =['<a id="a"><b id="b">hey!</b></a>'];
oBuilder.append(aFileParts[0]);var oMyBlob = oBuilder.getBlob("text/xml"); // the blob
var typedArray =GetTheTypedArraySomehow();var blob =newBlob([typedArray],{type:"application/octet-binary"}); // pass a useful mime type here
var url = URL.createObjectURL(blob);
// url will be something like: blob:d3958f5c-0777-0845-9dcf-2cb28783acaf
// now you can use the url in any context that regular URLs can be used in, for example img.src, etc.