JavaScripture
Contribute via GitHub Feedback

DataView : ArrayBufferView

DataViews allow heterogeneous access to data stored in an ArrayBuffer. Values can be read and stored at any byte offset without alignment constraints.

Constructors

new DataView(buffer : ArrayBuffer, [byteOffset = 0 : Number, [byteLength : Number]]) : DataView

Creates a new DataView for buffer at the specified offset. If length is not specified, buffer.byteLength - byteOffset will be used.

Example:

Run

Results:

 

Instance Properties

buffer : ArrayBuffer

Returns the underlying buffer for this.

Example:

Run

Results:

 

byteLength : Number

The length of this in bytes.

Example:

Run

Results:

 

byteOffset : Number

The offset into this.buffer where the view starts.

Example:

Run

Results:

 

Instance Methods

getBigInt64(byteOffset : Number, [littleEndian = false : Boolean]) : BigInt

Returns a signed 64 bit integer out of this at the specified offset. If littleEndian is true, the value will be read as little endian (least significant byte is at byteOffset and most significant at byteOffset + 7).

Example:

Run

Results:

 

getBigUint64(byteOffset : Number, [littleEndian = false : Boolean]) : BigInt

Returns an unsigned 64 bit integer out of this at the specified offset. If littleEndian is true, the value will be read as little endian (least significant byte is at byteOffset and most significant at byteOffset + 7).

Example:

Run

Results:

 

getFloat32(byteOffset : Number, [littleEndian = false : Boolean]) : Number

Returns a 32 bit floating point number out of this at the specified offset. If littleEndian is true, the value will be read as little endian (least significant byte is at byteOffset and most significant at byteOffset + 3).

Example:

Run

Results:

 

getFloat64(byteOffset : Number, [littleEndian = false : Boolean]) : Number

Returns a 64 bit floating point number out of this at the specified offset. If littleEndian is true, the value will be read as little endian (least significant byte is at byteOffset and most significant at byteOffset + 7).

Example:

Run

Results:

 

getInt16(byteOffset : Number, [littleEndian = false : Boolean]) : Number

Returns a signed 16 bit integer out of this at the specified offset. If littleEndian is true, the value will be read as little endian (least significant byte is at byteOffset and most significant at byteOffset + 1).

Example:

Run

Results:

 

getInt32(byteOffset : Number, [littleEndian = false : Boolean]) : Number

Returns a signed 32 bit integer out of this at the specified offset. If littleEndian is true, the value will be read as little endian (least significant byte is at byteOffset and most significant at byteOffset + 3).

Example:

Run

Results:

 

getInt8(byteOffset : Number) : Number

Returns a signed byte out of this at the specified offset.

Example:

Run

Results:

 

getUint16(byteOffset : Number, [littleEndian = false : Boolean]) : Number

Returns an unsigned 16 bit integer out of this at the specified offset. If littleEndian is true, the value will be read as little endian (least significant byte is at byteOffset and most significant at byteOffset + 1).

Example:

Run

Results:

 

getUint32(byteOffset : Number, [littleEndian = false : Boolean]) : Number

Returns an unsigned 32 bit integer out of this at the specified offset. If littleEndian is true, the value will be read as little endian (least significant byte is at byteOffset and most significant at byteOffset + 3).

Example:

Run

Results:

 

getUint8(byteOffset : Number) : Number

Returns an unsigned byte out of this at the specified offset.

Example:

Run

Results:

 

setBigInt64(byteOffset : Number, value : BigInt, [littleEndian = false : Boolean]) : undefined

Stores a signed 64 bit integer into this at the specified offset. If littleEndian is true, the value will be stored as little endian (least significant byte is at byteOffset and most significant at byteOffset + 7).

Example:

Run

Results:

 

setBigUint64(byteOffset : Number, value : BigInt, [littleEndian = false : Boolean]) : undefined

Stores an unsigned 64 bit integer into this at the specified offset. If littleEndian is true, the value will be stored as little endian (least significant byte is at byteOffset and most significant at byteOffset + 7).

Example:

Run

Results:

 

setFloat32(byteOffset : Number, value : Number, [littleEndian = false : Boolean]) : undefined

Converts value to a 32 bit floating point number and stores it into this at the specified offset. If littleEndian is true, the value will be stored as little endian (least significant byte is at byteOffset and most significant at byteOffset + 3).

Example:

Run

Results:

 

setFloat64(byteOffset : Number, value : Number, [littleEndian = false : Boolean]) : undefined

Stores value as a 64 bit floating point number in this at the specified offset. If littleEndian is true, the value will be stored as little endian (least significant byte is at byteOffset and most significant at byteOffset + 7).

Example:

Run

Results:

 

setInt16(byteOffset : Number, value : Number, [littleEndian = false : Boolean]) : undefined

Stores a signed 16 bit integer into this at the specified offset. If littleEndian is true, the value will be stored as little endian (least significant byte is at byteOffset and most significant at byteOffset + 1).

Example:

Run

Results:

 

setInt32(byteOffset : Number, value : Number, [littleEndian = false : Boolean]) : undefined

Stores a signed 32 bit integer into this at the specified offset. If littleEndian is true, the value will be stored as little endian (least significant byte is at byteOffset and most significant at byteOffset + 3).

Example:

Run

Results:

 

setInt8(byteOffset : Number, value : Number) : undefined

Stores a signed byte into this at the specified offset.

Example:

Run

Results:

 

setUint16(byteOffset : Number, value : Number, [littleEndian = false : Boolean]) : undefined

Stores an unsigned 16 bit integer into this at the specified offset. If littleEndian is true, the value will be stored as little endian (least significant byte is at byteOffset and most significant at byteOffset + 1).

Example:

Run

Results:

 

setUint32(byteOffset : Number, value : Number, [littleEndian = false : Boolean]) : undefined

Stores an unsigned 32 bit integer into this at the specified offset. If littleEndian is true, the value will be stored as little endian (least significant byte is at byteOffset and most significant at byteOffset + 3).

Example:

Run

Results:

 

setUint8(byteOffset : Number, value : Number) : undefined

Stores an unsigned byte into this at the specified offset.

Example:

Run

Results: