# buffer
A Node.js-compatible implementation of the core buffer
module
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
# poolSize
This is the size (in bytes) of pre-allocated internal Buffer
instances used for pooling. This value may be modified.
Default: 8192
# Methods
# alloc
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 |
fill | String | Number | buffer.Buffer | Uint8Array | A value to pre-fill the new |
encoding | String | If |
Returns
- Type
- buffer.Buffer
# allocUnsafe
Allocates a new Buffer
of size
bytes.
Parameters
Name | Type | Description |
---|---|---|
size | Number | The desired length of the new |
Returns
- Type
- buffer.Buffer
# allocUnsafeSlow
Allocates a new Buffer
of size
bytes.
Parameters
Name | Type | Description |
---|---|---|
size | Number | The desired length of the new |
Returns
- Type
- buffer.Buffer
# byteLength
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 |
Returns
- Type
- Number
# compare
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 |
Returns
Either -1
, 0
, or 1
, depending on the result of the comparison. See compare for details.
- Type
- Number
# concat
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 |
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.
- Type
- buffer.Buffer
# from
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 |
encodingOrOffset | String | Number | encoding of the string, or start offset of array/buffer |
length | Number | length of the underlying array/buffer to wrap |
Returns
- Type
- buffer.Buffer
# isBuffer
Returns true
if obj
is a Buffer
, false
otherwise.
Parameters
Name | Type | Description |
---|---|---|
obj | Object | The object to check if it is a |
Returns
- Type
- Boolean
# isEncoding
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