# buffer

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

Availability
8.2.0
8.2.0
9.2.0
Extends
Object

NOTE

This is an abstract type. Any object of this structure can be used where this type is used.

# Overview

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 (opens new window)

# Properties

# kMaxLength

Availability
8.2.0
8.2.0
9.2.0
kMaxLength :Number

The largest size allowed for a single buffer.Buffer instance.


# poolSize

Availability
8.2.0
8.2.0
9.2.0
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

# alloc

Availability
8.2.0
8.2.0
9.2.0
alloc(size[, fill[, encoding]]) buffer.Buffer

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

Parameters

Name Type Description
size Number

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.

Returns


# allocUnsafe

Availability
8.2.0
8.2.0
9.2.0
allocUnsafe(size) buffer.Buffer

Allocates a new Buffer of size bytes.

Parameters

Name Type Description
size Number

The desired length of the new Buffer.

Returns


# allocUnsafeSlow

Availability
8.2.0
8.2.0
9.2.0
allocUnsafeSlow(size) buffer.Buffer

Allocates a new Buffer of size bytes.

Parameters

Name Type Description
size Number

The desired length of the new Buffer.

Returns


# byteLength

Availability
8.2.0
8.2.0
9.2.0
byteLength(string[, encoding]) Number

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

Name Type Description
string String | buffer.Buffer | ArrayBuffer

A value to calculate the length of.

encoding String

If string is a string, this is its encoding.

Returns

Type
Number

# compare

Availability
8.2.0
8.2.0
9.2.0
compare(buf1, buf2) 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

Name Type Description
buf1 buffer.Buffer | Uint8Array

A value to calculate the length of.

buf2 buffer.Buffer | Uint8Array

If string is a string, this is its encoding.

Returns

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

Type
Number

# concat

Availability
8.2.0
8.2.0
9.2.0
concat(list[, totalLength]) buffer.Buffer

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

Name Type Description
list Array<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

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


# from

Availability
8.2.0
8.2.0
9.2.0
from(arg[, encodingOrOffset[, length]]) buffer.Buffer

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

Name Type Description
arg Array<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


# isBuffer

Availability
8.2.0
8.2.0
9.2.0
isBuffer(obj) Boolean

Returns true if obj is a Buffer, false otherwise.

Parameters

Name Type Description
obj Object

The object to check if it is a Buffer

Returns

Type
Boolean

# isEncoding

Availability
8.2.0
8.2.0
9.2.0
isEncoding(encoding) Boolean

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

Parameters

Name Type Description
encoding String

A character encoding name to check.

Returns

Type
Boolean

# Constants

# INSPECT_MAX_BYTES

Availability
8.2.0
8.2.0
9.2.0
INSPECT_MAX_BYTES :Number

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