javascript BlobBuilder 和新的 Blob 构造函数有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10412299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the difference between BlobBuilder and the new Blob constructor?
提问by neave
The W3 announced that they intend to deprecate the BlobBuilder APIin preference for the new Blob API.
W3 宣布他们打算弃用BlobBuilder API,而优先使用新的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:
如果我已经在 JavaScript 应用程序中使用 BlobBuilder,我该如何转换为使用这个新的 Blob API?旧的 WebKitBlobBuilder 在最新的 WebKit(和 Chrome Canary)中仍然可用,但很快就会被删除。在你可以写这样的东西之前:
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.
如何重写以使用新的 Blob 构造函数?谢谢你。
采纳答案by Alf Eaton
Passing an ArrayBuffer to the Blob constructor appears to be deprecated, so:
将 ArrayBuffer 传递给 Blob 构造函数似乎已被弃用,因此:
var dataView = new DataView(arrayBuffer);
var blob = new Blob([dataView], { type: mimeString });
回答by GillesC
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)
[Constructor, Constructor((ArrayBuffer or Blob or DOMString)
回答by emk
var blob = new Blob([arrayBuffer], {type: mimeString});