Data()
Description
Creates an instance of Data.
The following options are supported for the encoding parameter:
- "utf8" (default) - Encode the text as UTF-8
- "hex" - Decode the text as hexadecimal representation
- "base64" - Decode the text as Base64 format
- "base64url" - Decode the text as Base64URL format
When decoding is required but fails, a runtime error is generated to stop the script. This is different from Data.from() where null is returned to indicate the error.
Syntax
new Data()new Data(data)new Data(text)new Data(text, encoding)new Data(byteArray)
Parameters
new Data()
An empty Data object.
new Data(bytes)
Creates an instance of Data from an array of bytes.
An array of numbers representing the bytes.
A Data object containing the bytes from the array.
new Data(text, encoding?)
Creates an instance of Data from a string.
A string to encode or decode into bytes.
A Data object converted from the string.
new Data(data)
Creates an instance of Data by copying bytes from another Data object.
A Data object to copy bytes from.
A Data object copied from the other Data object.