Skip to content
Titanium SDK
Version13.3.0

You are reading 13.3.0. See this page in 13.4.1.

Titanium.Buffer

proxyAndroidiPhoneiPadmacOSsince Android 1.7, iPhone 1.7, iPad 1.7, macOS 9.2.0

Extends Titanium.Proxy

Buffer is a mutable, resizable container for raw data.

A Buffer works like a resizable array of byte values.

Use the Titanium.createBuffer method to create a buffer.

Properties 7

apiName

Stringsince Android 3.2.0, iPhone 3.2.0, iPad 3.2.0, macOS 9.2.0read-only

Inherited from Titanium.Proxy

The name of the API that this proxy corresponds to.

bubbleParent

Booleansince Android 3.0.0, iPhone 3.0.0, iPad 3.0.0, macOS 9.2.0

Inherited from Titanium.Proxy

Indicates if the proxy will bubble an event to its parent.

Default: true

length

Number

Length of the buffer in bytes.

When length is modified the buffer will be re-sized while preserving existing data where possible. If the new buffer length is smaller than the length of the existing data then the existing data will be truncated down to the size of the new buffer.

Resizing a buffer by setting its length should be used sparingly due to the associated overhead.

Default: 0 unless `value` is specified, in which case the length of the encoded data is used.

type

String

The type of data encoding to use with value.

Required when value is a Number. For numbers, specify a TYPE constant from Titanium.Codec, for example, Titanium.Codec.TYPE_DOUBLE.

When value is a String, specify a CHARSET constant from Titanium.Codec.

Default: For string values, defaults to <Titanium.Codec.CHARSET_UTF8>.

Methods 13

Inherited from Titanium.Proxy

Adds the specified callback as an event listener for the named event.

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to invoke when the event is fired.

4 fields
bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

Appends sourceBuffer to the this buffer.

This buffer is grown dynamically to accommodate the additional data if need be.

If sourceOffset and sourceLength are specified, data from sourceBuffer is copied starting at position sourceOffset, and no more than sourceLength bytes are copied.

Parameters
ParametersTypeDescription
sourceBufferTitanium.Buffer

Buffer to append to this buffer.

sourceOffset?Number

Offset to start reading buffer data from. If specified, sourceLength must also be specified.

sourceLength?Number

Number of bytes to read from sourceBuffer. If specified, sourceOffset must also be specified.

Returns Number

The number of bytes appended.

Clears this buffer's contents but does not change the size of the buffer.

Creates a complete or partial copy of this buffer.

If called with no arguments, returns a complete copy of the current buffer.

If offset and length are specified, creates a new buffer from the original buffer contents starting at offset and ending at offset+length-1.

Parameters
ParametersTypeDescription
offset?Number

Offset of first byte of this buffer to clone. If specified, length must be specified as well.

length?Number

Number of bytes of data to clone.

Copies data from sourceBuffer into the current buffer at offset.

Does not expand this buffer if there is not enough room to accommodate the data from sourceBuffer.

If sourceOffset and sourceLength are specified, bytes are copied from sourceBuffer starting at sourceOffset, and a maximum of sourceLength bytes are copied.

Parameters
ParametersTypeDescription
sourceBufferTitanium.Buffer

Buffer to copy data from.

offsetNumber

Offset in this buffer for the first byte of the copied data.

sourceOffset?Number

Offset in sourceBuffer to copy data from. If specified, sourceLength must be specified as well.

sourceLength?Number

Number of bytes to copy from sourceBuffer. If specified, sourceOffset must be specified as well.

Returns Number

The number of bytes copied.

Fills this buffer with the specified byte value.

Fills the buffer by setting byte values to fillByte.

If offset and length are specified, fills the buffer starting at offset and ending at offset+length-1.

If offset and length are omitted, fills the entire buffer.

Parameters
ParametersTypeDescription
fillByteNumber

Byte to fill buffer with.

offset?Number

Offset of the first byte to set to fillByte.

length?Number

Number of bytes to fill.

Inherited from Titanium.Proxy

Fires a synthesized event to any registered listeners.

Parameters
ParametersTypeDescription
nameString

Name of the event.

event?Dictionary

A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

Inserts data from sourceBuffer into this buffer at offset.

Buffer is grown to accommodate the new data.

If sourceOffset and sourceLength are specified, sourceLength bytes of data are copied from sourceBuffer, with the first byte at sourceOffset.

Parameters
ParametersTypeDescription
sourceBufferTitanium.Buffer

Buffer holding data to insert into this buffer.

offsetNumber

Offset in this buffer to insert the first byte copied from sourceBuffer.

sourceOffset?Number

Offset in sourceBuffer of the first byte to insert. If specified, sourceLength must be specified as well.

sourceLength?Number

Number of bytes to insert from sourceBuffer. If specified, sourceOffset must be specified as well.

Returns Number

The number of bytes inserted.

Releases the space allocated to the buffer, and sets its length to 0.

This is effectively the same as buffer.length = 0.

Inherited from Titanium.Proxy

Removes the specified callback as an event listener for the named event.

Parameters
ParametersTypeDescription
nameString

Name of the event.

callbackCallback<Titanium.Event>

Callback function to remove. Must be the same function passed to addEventListener.

4 fields
bubbles Boolean

True if the event will try to bubble up if possible.

cancelBubble Boolean

Set to true to stop the event from bubbling.

source Object

Source object that fired the event.

type String

Name of the event fired.

Converts this buffer to a String.

Returns String