What's the difference between BlobBuilder and the new Blob constructor?

瘦欲@ 提交于 2019-12-08 23:19:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!