Class: ByteArray

ink/strings/binary~ ByteArray

new ByteArray(contentOrLength, charset)

Constructs a writable and growable byte array.

If the first argument to this constructor is a number, it specifies the initial length of the ByteArray in bytes.

Else, the argument defines the content of the ByteArray. If the argument is a String, the constructor requires a second argument containing the name of the String's encoding. If called without arguments, an empty ByteArray is returned.

The constructor also accepts a Node.js Buffer.

Also, if you pass in Number as the first argument and "false" as the second, then the newly created array will not be cleared.

Parameters:
Name Type Argument Description
contentOrLength Binary | Array | String | Number | Buffer

Content or length of the ByteArray.

charset String <optional>

The encoding name if the first argument is a String.

Source:

Extends

Methods

byteAt(offset) → {Number}

Returns the byte at the given offset as a ByteString.

Parameters:
Name Type Description
offset Number
Source:
Returns:
Type
Number

concat() → {ByteArray}

Returns a ByteArray composed of itself concatenated with the given ByteString, ByteArray, and Array values.

Parameters:
Name Type Description
arg... Binary | Array

one or more elements to concatenate

Source:
Returns:

a new ByteArray

Type
ByteArray

every(callback, thisObj) → {Boolean}

Tests whether all elements in the array pass the test implemented by the provided function.

Parameters:
Name Type Argument Description
callback function

the callback function

thisObj Object <optional>

optional this-object for callback

Source:
Returns:

true if every invocation of callback returns true

Type
Boolean

filter(callback, thisObj) → {ByteArray}

Return a ByteArray containing the elements of this ByteArray for which the callback function returns true.

Parameters:
Name Type Argument Description
callback function

the filter function

thisObj Object <optional>

optional this-object for callback

Source:
Returns:

a new ByteArray

Type
ByteArray

forEach(fn, thisObj)

Apply a function for each element in the ByteArray.

Parameters:
Name Type Argument Description
fn function

the function to call for each element

thisObj Object <optional>

optional this-object for callback

Source:

get(offset) → {ByteString}

Returns the byte at the given offset.

Parameters:
Name Type Description
offset Number
Inherited From:
Source:
Returns:
Type
ByteString

indexOf(sequence, start, stop) → {Number}

Returns the index of the first occurrence of sequence (a Number or a ByteString or ByteArray of any length), or -1 if none was found. If start and/or stop are specified, only elements between the indexes start and stop are searched.

Parameters:
Name Type Description
sequence Number | Binary

the number or binary to look for

start Number

optional index position at which to start searching

stop Number

optional index position at which to stop searching

Inherited From:
Source:
Returns:

the index of the first occurrence of sequence, or -1

Type
Number

lastIndexOf(sequence, start, stop) → {Number}

Returns the index of the last occurrence of sequence (a Number or a ByteString or ByteArray of any length) or -1 if none was found. If start and/or stop are specified, only elements between the indexes start and stop are searched.

Parameters:
Name Type Description
sequence Number | Binary

the number or binary to look for

start Number

optional index position at which to start searching

stop Number

optional index position at which to stop searching

Inherited From:
Source:
Returns:

the index of the last occurrence of sequence, or -1

Type
Number

map(callback, thisObj) → {ByteArray}

Returns a new ByteArray whose content is the result of calling the provided function with every element of the original ByteArray

Parameters:
Name Type Argument Description
callback function

the callback

thisObj Object <optional>

optional this-object for callback

Source:
Returns:

a new ByteArray

Type
ByteArray

pop() → {Number}

Removes the last element from an array and returns that element.

Source:
Returns:
Type
Number

push() → {Number}

Appends the given elements and returns the new length of the array.

Parameters:
Name Type Argument Description
num... Number <repeatable>

one or more numbers to append

Source:
Returns:

the new length of the ByteArray

Type
Number

reduce(callback, initialValue) → {*}

Apply a function to each element in this ByteArray as to reduce its content to a single value.

Parameters:
Name Type Argument Description
callback function

the function to call with each element of the ByteArray

initialValue * <optional>

optional argument to be used as the first argument to the first call to the callback

Source:
See:
Returns:

the return value of the last callback invocation

Type
*

reduceRight(callback, initialValue) → {*}

Apply a function to each element in this ByteArray starting at the last element as to reduce its content to a single value.

Parameters:
Name Type Argument Description
callback function

the function to call with each element of the ByteArray

initialValue * <optional>

optional argument to be used as the first argument to the first call to the callback

Source:
See:
Returns:

the return value of the last callback invocation

Type
*

reverse() → {ByteArray}

Reverses the content of the ByteArray in-place

Source:
Returns:

this ByteArray with its elements reversed

Type
ByteArray

shift() → {Number}

Removes the first element from the ByteArray and returns that element. This method changes the length of the ByteArray

Source:
Returns:

the removed first element

Type
Number

slice(begin, end) → {ByteArray}

Returns a new ByteArray containing a portion of this ByteArray.

Parameters:
Name Type Description
begin Number

Zero-based index at which to begin extraction. As a negative index, begin indicates an offset from the end of the sequence.

end Number

Zero-based index at which to end extraction. slice extracts up to but not including end. As a negative index, end indicates an offset from the end of the sequence. If end is omitted, slice extracts to the end of the sequence.

Source:
Returns:

a new ByteArray

Type
ByteArray

some(callback, thisObj) → {Boolean}

Tests whether some element in the array passes the test implemented by the provided function.

Parameters:
Name Type Argument Description
callback function

the callback function

thisObj Object <optional>

optional this-object for callback

Source:
Returns:

true if at least one invocation of callback returns true

Type
Boolean

sort(compareFunction)

Sorts a ByteArray.

Parameters:
Name Type Argument Description
compareFunction function <optional>

A function to be executed against each element in the ByteArray If not present, the bytes are compared numerically. Otherwise it works like a regular JS array sorter

Source:

splice(index, howMany)

Changes the content of the ByteArray, adding new elements while removing old elements.

Parameters:
Name Type Argument Description
index Number

the index at which to start changing the ByteArray

howMany Number

The number of elements to remove at the given position

elements... Number <repeatable>

the new elements to add at the given position

Source:

split(delimiter, options) → {array.<ByteArray>}

Split at delimiter, which can by a Number, a ByteString, a ByteArray or an Array of the prior (containing multiple delimiters, i.e., "split at any of these delimiters"). Delimiters can have arbitrary size.

Parameters:
Name Type Description
delimiter Number | Binary

one or more delimiter items

options Object

optional object parameter with the following optional properties:

<ul> <li>count - Maximum number of elements (ignoring delimiters) to return. The last returned element may contain delimiters.</li> <li>includeDelimiter - Whether the delimiter should be included in the result.</li> </ul>

Source:
Returns:
Type
array.<ByteArray>

toArray(charset) → {array}

Returns an array containing the bytes as numbers.

Parameters:
Name Type Description
charset String

optional the name of the string encoding

Inherited From:
Source:
Returns:
Type
array

toByteArray() → {ByteArray}

Returns a ByteArray

Source:
Returns:
Type
ByteArray

toByteString() → {ByteString}

Returns a ByteString

Source:
Returns:
Type
ByteString

toString(charset) → {string}

Returns a String representation of the ByteArray.

Parameters:
Name Type Argument Description
charset string <optional>

The charset to use to create the string

Source:
Returns:
Type
string

unshift() → {Number}

Adds one or more elements to the beginning of the ByteArray and returns its new length.

Parameters:
Name Type Argument Description
num... Number <repeatable>

one or more numbers to append

Source:
Returns:

the new length of the ByteArray

Type
Number
See NOTICE.md for licenses
ink-strings Copyright contributers to ink-strings, base64, Helma, RingoJS, sprintf projects.
Documentation generated by JSDoc 3.2.0-dev on Sun Jun 09 2013 11:56:08 GMT-0400 (EDT) using the DocStrap template.