ftos.convert.string.toByteArray
Decodes a string using a specified character encoding and returns an object conforming to the IFtosWorkflowBlob interface, which exposes the byte length of the decoded binary data. This is useful for determining the size of the decoded content without exposing the raw bytes or as input for other methods such as ftos.convert.byteArray.toHex.
The returned object does not provide direct access to the underlying byte array. However, internally, the string must be decoded into a byte array as an intermediate step to determine the byte length of the binary data.
Syntax
ftos.convert.string.toByteArray(input: string, encoding: "utf7" | "utf8" | "utf32" | "unicode" | "ascii"): IFtosWorkflowBlob
| Parameter | Type | Description |
|---|---|---|
input
|
string | Input string to decode. |
encoding
|
string | Character encoding used to interpret the input string. Possible values:
|
Return Value
Returns an IFtosWorkflowBlob object.
Interfaces
IFtosWorkflowBlob
A binary data container exposing only the byte length of the data through a read-only length property, without providing direct access to the underlying bytes.
interface IFtosWorkflowBlob {
readonly length: number;
}
| Property | Type | Description |
|---|---|---|
length
|
number | Number of bytes of the binary data. |
Encoding and Byte Length Variations
The byte length depends on both the encoding and the actual characters in the input:
- ASCII – 1 byte per character (values 0–127). Cannot represent characters outside this range directly.
- UTF-8 – Variable-length; 1 byte for Basic Latin characters, 2–4 bytes for characters outside this range.
- Unicode (UTF-16 LE) – 2 bytes for Basic Multilingual Plane (BMP) characters. Characters outside BMP (e.g., certain emoji) use 4 bytes via surrogate pairs.
- UTF-32 – Fixed-length; 4 bytes per character regardless of code point.
- UTF-7 – Variable-length; Basic Latin characters use 1 byte, while other characters are encoded in longer Base64-like sequences.
Examples
This example:
- Calculates the byte length of the Hello World Unicode encoded string.
- Stores the result (which is 22) in the baseDataLength variable.
var baseDataLength = ftos.convert.string.toByteArray('Hello World', 'unicode').length;
Although "Hello World" contains 11 characters, the result is 22 because in UTF-16 (the
unicode option), each Basic Latin character is encoded using 2 bytes.This example:
- Calculates the byte length of the Hello ☺ UTF-8 encoded string.
- Stores the result (which is 9) in the baseDataLengthEmoji variable.
var baseDataLengthEmoji = ftos.convert.string.toByteArray('Hello ☺', 'utf8').length;
Explanation:
- "Hello " - 6 ASCII characters × 1 byte: 6 bytes
- ☺ (U+263A in UTF-8): 3 bytes
- Total: 6 bytes + 3 bytes =9 bytes