new ByteString(content, charset)
Constructs an immutable byte string.
If the first argument is a String, the constructor requires a second argument containing the name of the String's encoding. If called without arguments, an empty ByteString is returned.
The constructor also accepts a Node.js Buffer.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
content |
Binary | Array | String | Buffer | The content of the ByteString. |
|
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() → {ByteString}
-
Returns a ByteString 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 ByteString
- Type
- ByteString
-
copy(start, end, target, targetStart)
-
Copy a range of bytes between start and stop from this ByteString to a target ByteArray at the given targetStart offset.
Parameters:
Name Type Description start
Number end
Number target
ByteArray targetStart
Number - 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
-
slice(begin, end) → {ByteString}
-
Returns a new ByteString containing a portion of this ByteString.
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 ByteString
- Type
- ByteString
-
split(delimiter, options) → {array}
-
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
-
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 byte for byte copy of this immutable ByteString as a mutable ByteArray.
- Source:
Returns:
- Type
- ByteArray
-
toByteString() → {ByteString}
-
Returns this ByteString itself.
- Source:
Returns:
- Type
- ByteString
-
toString() → {string}
-
Returns a debug representation such as
"[ByteString 10]"
where 10 is the length of this ByteString.- Source:
Returns:
- Type
- string