Blobs and Buffers Flashcards

1
Q

What does a blob consist of in JS?

A

Blob consists of an optional string type (a MIME-type usually), plus blobParts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the constructor to create a new Blob?

A

new Blob(blobParts, options);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What should the blobParts argument be in this constructor
new Blob(blobParts, options);

A

blobParts is an array of Blob/BufferSource/String values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What should options be in this constructor
new Blob(blobParts, options);

A

an optional object with properties, type and endings:

  • type – Blob type, usually MIME-type, e.g. image/png,
  • endings – whether to transform end-of-line to make the Blob correspond to current OS newlines (\r\n or \n). By default “transparent” (do nothing), but also can be “native” (transform).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is an ArrayBuffer?

A

The basic binary object is ArrayBuffer – a reference to a fixed-length contiguous memory area.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the following code do?
let buffer = new ArrayBuffer(16); // create a buffer of length 16
alert(buffer.byteLength); // 16

A

This allocates a contiguous memory area of 16 bytes and pre-fills it with zeroes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

ArrayBuffer is not an array of something, give 3 reasons why?

A

It has a fixed length, we can’t increase or decrease it.

It takes exactly that much space in the memory.

To access individual bytes, another “view” object is needed, not buffer[index].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you manipulate an array buffer?

A

To manipulate an ArrayBuffer, we need to use a “view” object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does a view object store?

A

A view object does not store anything on its own. It’s the “eyeglasses” that give an interpretation of the bytes stored in the ArrayBuffer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does the Uint8Array view the bytes in an array buffer?

A

Uint8Array – treats each byte in ArrayBuffer as a separate number, with possible values from 0 to 255 (a byte is 8-bit, so it can hold only that much). Such value is called a “8-bit unsigned integer”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does the Uint16Array view the bytes in an array buffer?

A

Uint16Array – treats every 2 bytes as an integer, with possible values from 0 to 65535. That’s called a “16-bit unsigned integer”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the common term for all these views (Uint8Array, Uint32Array, etc)?

A

Typed Array is the common term for all these views (Uint8Array, Uint32Array, etc). They share the same set of methods and properties.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

ArrayBuffer is a memory area. (repeat this to memorize) What’s stored in it?

A

a raw sequence of bytes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Is there a TypedArray constructor?

A

There is no constructor called TypedArray, it’s just a common “umbrella” term to represent one of the views over ArrayBuffer: Int8Array, Uint8Array and so on,

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Do Typed arrays behave like regular arrays?

A

Yes, Typed arrays behave like regular arrays: they have indexes and are iterable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly