# buffer

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

- Source: https://titaniumsdk.com/docs/sdk/12.6.3/buffer
- Titanium SDK version: 12.6.3
- Kind: pseudo
- Platforms: Android, iPhone, iPad, macOS
- Since: Titanium SDK 8.2.0

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](https://nodejs.org/api/buffer.html)

## Properties

### INSPECT_MAX_BYTES

- Type: Number
- Platforms: Android, iPhone, iPad, macOS
- Default: `50`

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

### kMaxLength

- Type: Number
- Platforms: Android, iPhone, iPad, macOS

The largest size allowed for a single [buffer.Buffer](https://titaniumsdk.com/docs/sdk/buffer.Buffer.md) instance.

### poolSize

- Type: Number
- Platforms: Android, iPhone, iPad, macOS
- Default: `8192`

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

## Methods

### alloc

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `size` (Number): The desired length of the new `Buffer`.
- `fill` (String | Number | buffer.Buffer | Uint8Array, optional): A value to pre-fill the new `Buffer` with. Default: `0`.
- `encoding` (String, optional): If `fill` is a string, this is its encoding. Default: ``'utf8'``.

Returns: buffer.Buffer

### allocUnsafe

- Platforms: Android, iPhone, iPad, macOS

Allocates a new `Buffer` of `size` bytes.

Parameters:

- `size` (Number): The desired length of the new `Buffer`.

Returns: buffer.Buffer

### allocUnsafeSlow

- Platforms: Android, iPhone, iPad, macOS

Allocates a new `Buffer` of `size` bytes.

Parameters:

- `size` (Number): The desired length of the new `Buffer`.

Returns: buffer.Buffer

### byteLength

- Platforms: Android, iPhone, iPad, macOS

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:

- `string` (String | buffer.Buffer | ArrayBuffer): A value to calculate the length of.
- `encoding` (String, optional): If `string` is a string, this is its encoding. Default: ``'utf8'``.

Returns: Number

### compare

- Platforms: Android, iPhone, iPad, macOS

Compares `buf1` to `buf2`, typically for the purpose of sorting arrays of [buffer.Buffer](https://titaniumsdk.com/docs/sdk/buffer.Buffer.md) instances. This is equivalent to calling `buf1.compare(buf2)`.

Parameters:

- `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: Number - Either `-1`, `0`, or `1`, depending on the result of the comparison. See [buffer.Buffer.compare](https://titaniumsdk.com/docs/sdk/buffer.Buffer.md#compare) for details.

### concat

- Platforms: Android, iPhone, iPad, macOS

Returns a new [buffer.Buffer](https://titaniumsdk.com/docs/sdk/buffer.Buffer.md) which is the result of concatenating all the [buffer.Buffer](https://titaniumsdk.com/docs/sdk/buffer.Buffer.md) 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:

- `list` (Array<buffer.Buffer> | Array<Uint8Array>): List of `Buffer` or `Uint8Array` instances to concatenate.
- `totalLength` (Number, optional): 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](https://titaniumsdk.com/docs/sdk/buffer.Buffer.md#compare) for details.

### from

- Platforms: Android, iPhone, iPad, macOS

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:

- `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](https://titaniumsdk.com/docs/sdk/Titanium.Buffer.md) to wrap.
- `encodingOrOffset` (String | Number, optional): encoding of the string, or start offset of array/buffer
- `length` (Number, optional): length of the underlying array/buffer to wrap

Returns: buffer.Buffer

### isBuffer

- Platforms: Android, iPhone, iPad, macOS

Returns `true` if `obj` is a `Buffer`, `false` otherwise.

Parameters:

- `obj` (Object): The object to check if it is a `Buffer`

Returns: Boolean

### isEncoding

- Platforms: Android, iPhone, iPad, macOS

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

Parameters:

- `encoding` (String): A character encoding name to check.

Returns: Boolean

---

- This corpus documents Titanium SDK 13.4.1. Anything here that does not name a version describes 13.4.1.
- Titanium is maintained by TiDev. The Appcelerator toolchain is retired: there is no `appc` CLI, no Appcelerator Studio and no hosted build service. The supported CLI is `titanium` on npm, invoked as `ti`.

