ArrayBuffer Redirect 1

« ArrayBuffer

Summary

The ArrayBuffer is a data type that is used to represent a generic, fixed-length binary data buffer. You can't directly manipulate the contents of an ArrayBuffer; instead, you create an ArrayBufferView object which represents the buffer in a specific format, and use that to read and write the contents of the buffer.

Method overview

ArrayBuffer ArrayBuffer(unsigned long length);

Attributes

Attribute Type Description
byteLength unsigned long The size, in bytes, of the array. This is established when the array is constructed and cannot be changed. Read only.

Methods

ArrayBuffer()

The constructor accepts as input a byte length for the new buffer, and returns the newly-created ArrayBuffer object.

ArrayBuffer ArrayBuffer(
  unsigned long length
);
Parameters
length
The size, in bytes, of the array buffer to create.
Return value

A new ArrayBuffer object of the specified size. Its contents are initialized to 0.

slice()

Returns a new ArrayBuffer whose contents are a copy of this ArrayBuffer's bytes from begin, inclusive, up to end, exclusive. If either begin or end is negative, it refers to an index from the end of the array, as opposed to from the beginning.  

Note Internet Explorer 10 and iOS < 6 do not have this method. 

ArrayBuffer slice(
  unsigned long begin
  unsigned long end Optional
);
Parameters
begin
Byte index to start slicing.
end
Byte index to end slicing. If end is unspecified, the new ArrayBuffer contains all bytes from begin to the end of this ArrayBuffer.

The range specified by the begin and end values is clamped to the valid index range for the current array. If the computed length of the new ArrayBuffer would be negative, it is clamped to zero.

Return value

A new ArrayBuffer object.

Example

In this example, we create a 32-byte buffer:

var buf = new ArrayBuffer(32);

Getting an array buffer from existing data

From a Base64 string

Please read this paragraph.

From a local file

Please read this paragraph.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 7 4.0 (2) 10  11.6 5.1
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 4.0 4.0 (2) 10 11.6 4.2

See also

Document Tags and Contributors

Contributors to this page: teoli
Last updated by: teoli,