ArrayBuffer和Blob有什么区别? [英] What is the difference between an ArrayBuffer and a Blob?

查看:1957
本文介绍了ArrayBuffer和Blob有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 http://www.html5rocks.com/en/tutorials / file / xhr2 / 并试图找出ArrayBuffer和Blob之间的区别。

I'm reading http://www.html5rocks.com/en/tutorials/file/xhr2/ and trying to figure out the difference between an ArrayBuffer and a Blob.

两个容器都不是由位组成的吗?因此,不能以多种方式查看两个容器(如32位块,16位块等)?

Aren't both containers comprised of bits? Hence, couldn't both containers be viewed in many ways (as 32-bit chunks, 16-bit chunks, etc.)?

推荐答案

在页面上对此进行了解释。

It's explained on the page.

ArrayBuffer

ArrayBuffer


ArrayBuffer是二进制数据的通用固定长度容器。如果您需要原始数据的通用缓冲区,它们非常方便,但这些人背后的真正力量是您可以使用JavaScript类型数组创建基础数据的视图。实际上,可以从单个ArrayBuffer源创建多个视图。例如,您可以创建一个8位整数数组,该数组与来自相同数据的现有32位整数数组共享相同的ArrayBuffer。基础数据保持不变,我们只是创建它的不同表示。

An ArrayBuffer is a generic fixed-length container for binary data. They are super handy if you need a generalized buffer of raw data, but the real power behind these guys is that you can create "views" of the underlying data using JavaScript typed arrays. In fact, multiple views can be created from a single ArrayBuffer source. For example, you could create an 8-bit integer array that shares the same ArrayBuffer as an existing 32-bit integer array from the same data. The underlying data remains the same, we just create different representations of it.

BLOB


如果您想直接使用Blob和/或不需要操作任何文件的字节,请使用xhr.responseType ='blob':

If you want to work directly with a Blob and/or don't need to manipulate any of the file's bytes, use xhr.responseType='blob':

这篇关于ArrayBuffer和Blob有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆