Skip to content
Titanium SDK
Version13.0.1

You are reading 13.0.1. See this page in 13.4.1.

buffer

pseudoAndroidiPhoneiPadmacOSsince 8.2.0

A Node.js-compatible implementation of the core buffer module

Titanium provides a number of shims and ports of core Node.js module functionality.

This module is intended to provide a Node-compatible port of the buffer.

More details on the Node.js API can be found in their buffer module documentation

Properties 3

The maximum number of bytes that will be returned when buf.inspect() is called. This can be overridden by user modules.

Default: 50

poolSize

Number

This is the size (in bytes) of pre-allocated internal Buffer instances used for pooling. This value may be modified.

Default: 8192

Methods 9

Allocates a new Buffer of size bytes. If fill is undefined, the Buffer will be zero-filled.

Parameters
ParametersTypeDescription
sizeNumber

The desired length of the new Buffer.

fill?String | Number | buffer.Buffer | Uint8Array

A value to pre-fill the new Buffer with.

encoding?String

If fill is a string, this is its encoding.

Allocates a new Buffer of size bytes.

Parameters
ParametersTypeDescription
sizeNumber

The desired length of the new Buffer.

Allocates a new Buffer of size bytes.

Parameters
ParametersTypeDescription
sizeNumber

The desired length of the new Buffer.

Returns the byte length of a string when encoded using encoding. This is not the same as String.prototype.length, which does not account for the encoding that is used to convert the string into bytes.

Parameters
ParametersTypeDescription
stringString | buffer.Buffer | ArrayBuffer

A value to calculate the length of.

encoding?String

If string is a string, this is its encoding.

Returns Number

Compares buf1 to buf2, typically for the purpose of sorting arrays of buffer.Buffer instances. This is equivalent to calling buf1.compare(buf2).

Parameters
ParametersTypeDescription
buf1buffer.Buffer | Uint8Array

A value to calculate the length of.

buf2buffer.Buffer | Uint8Array

If string is a string, this is its encoding.

Returns Number

Either -1, 0, or 1, depending on the result of the comparison. See buffer.Buffer.compare for details.

Returns a new buffer.Buffer which is the result of concatenating all the buffer.Buffer instances in the list together.

If the list has no items, or if the totalLength is 0, then a new zero-length Buffer is returned.

Parameters
ParametersTypeDescription
listArray<buffer.Buffer> | Array<Uint8Array>

List of Buffer or Uint8Array instances to concatenate.

totalLength?Number

Total length of the Buffer instances in list when concatenated.

Returns buffer.Buffer

Either -1, 0, or 1, depending on the result of the comparison. See buffer.Buffer.compare for details.

Allocates a new Buffer using an array of bytes in the range 0 – 255. Array entries outside that range will be truncated to fit into it.

Parameters
ParametersTypeDescription
argArray<Number> | buffer.Buffer | String | Titanium.Buffer | Uint8Array

The array of bytes to wrap in a Buffer, Buffer to copy, String to decode into bytes, or Titanium.Buffer to wrap.

encodingOrOffset?String | Number

encoding of the string, or start offset of array/buffer

length?Number

length of the underlying array/buffer to wrap

Returns true if obj is a Buffer, false otherwise.

Parameters
ParametersTypeDescription
objObject

The object to check if it is a Buffer

Returns Boolean

Returns true if encoding is the name of a supported character encoding, or false otherwise.

Parameters
ParametersTypeDescription
encodingString

A character encoding name to check.

Returns Boolean