What is the difference between an ArrayBuffer and a Blob?

后端 未结 2 1441
南笙
南笙 2020-12-12 12:45

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

Ar

2条回答
  •  难免孤独
    2020-12-12 13:36

    It's explained on the page.

    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

    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':

提交回复
热议问题