问题
The W3 announced that they intend to deprecate the BlobBuilder API in preference for the new Blob API.
If I am already using BlobBuilder in a JavaScript app, how can I convert to using this new Blob API? The old WebKitBlobBuilder is still available in the latest WebKit (and Chrome Canary), but it will soon be removed. Before you could write something like this:
var bb = new BlobBuilder();
bb.append(arrayBuffer);
var blob = bb.getBlob(mimeString);
How could this be rewritten to use the new Blob constructor? Thank you.
回答1:
Passing an ArrayBuffer to the Blob constructor appears to be deprecated, so:
var dataView = new DataView(arrayBuffer);
var blob = new Blob([dataView], { type: mimeString });
回答2:
From what the specs says it should be as simple as this. Just check the examples of the page you posted.
var blob = new Blob(arrayBuffer);
[Constructor, Constructor((ArrayBuffer or Blob or DOMString)
回答3:
var blob = new Blob([arrayBuffer], {type: mimeString});
来源:https://stackoverflow.com/questions/10412299/whats-the-difference-between-blobbuilder-and-the-new-blob-constructor