Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 324
neave Avatar asked May 02 '12 10:05

neave


Video Answer


2 Answers

Passing an ArrayBuffer to the Blob constructor appears to be deprecated, so:

var dataView = new DataView(arrayBuffer);
var blob = new Blob([dataView], { type: mimeString });
like image 134
Alf Eaton Avatar answered Oct 05 '22 16:10

Alf Eaton


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)

like image 26
GillesC Avatar answered Oct 05 '22 15:10

GillesC