ArrayBuffer与Blob和XHR2 [英] ArrayBuffer vs Blob and XHR2

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

问题描述

XHR2差异状态

能够传输ArrayBuffer,Blob,File和FormData对象.

The ability to transfer ArrayBuffer, Blob, File and FormData objects.

  • ArrayBuffer Blob 吗?
  • 我为什么要关心能够通过XHR2发送它们? (我可以理解File和FormData的价值)
    • What are the differences between ArrayBuffer and Blob ?
    • Why should I care about being able to send them over XHR2 ? (I can understand value of File and FormData)
    • 推荐答案

      这是为了替换旧方法,该方法将采用字符串"并将其部分切掉.

      This is an effort to replace the old method which would take a "string" and cut sections of it out.

      在需要类型化数组时,您将使用ArrayBuffer,因为您打算使用数据;而在只需要文件数据时,将使用blob.

      You would use an ArrayBuffer when you need a typed array because you intend to work with the data, and a blob when you just need the data of the file.

      Blob(无论如何都符合规范)具有MIME的空间,并且比其他格式(它更原生)更易于放入HTML5文件API.

      Blobs (according to spec anyway) have space for a MIME and easier to put into the HTML5 file API than other formats (it's more native to it).

      通过ArrayBuffer,我们可以处理带类型的数组,这比字符串操作处理特定字节要快得多,并且可以定义数组段实际上是什么类型.由于JavaScript的类型不是严格的,因此很难将文件分解为32位int或64位浮点数的数组(想像一下8位int -就字符串操作和按位性能而言,这将是一场噩梦)计算,尤其是使用unicode).

      The ArrayBuffer lets us work with typed arrays which is much faster than string manipulation to work with specific bytes and lets us define what type the array segments actually are. Since JavaScript is not strictly typed, it's hard to take a file that might be broken into an array of 32bit ints or perhaps 64bit floats (just imagine 8 bit ints-- that'd be a nightmare in terms of performance with string manipulation and bitwise calculations, especially with unicode).

      据我所知,您始终可以将blob移动到数组缓冲区或字符串表示形式,但这是XHR固有的功能,它可以使脚本更快,这是主要优点.

      As far as I can tell you can always move a blob to an array buffer or to a string representation, but this being native to XHR allows scripts to be faster which is the main advantage.

      我将使用blob来处理文件API,但是我将使用数组对数据执行预先计算.

      I'd use a blob for working with the file API, but I'd use the array for preforming computation on the data.

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

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