Class: IConvTextEncoder

bre/lib/text-encoders.IConvTextEncoder

The text encoder which uses iconv-lite package.

The iconv package supports legacy Japanese encodings -- Shift_JIS, EUC-JP.
The list of supported encodings is here.

const bre = require("bre")
bre.setTextEncoder(require("bre/lib/text-encoders/iconv"))

const ExampleRecord = bre.defineObjectRecord("ExampleRecord", [
    {type: "string(15)", name: "s"},
    {type: "utf8(32)", name: "utf8"},
    {type: "shift_jis(32)", name: "sjis"},
])

Note: This encoder depends on Node.js Buffer, so does not fit to browsers.
Note: You requires to install iconv-lite before a use of this.

$ npm install --save iconv-lite

Constructor

new IConvTextEncoder()

Source:

Methods

decode(data, byteOffset, byteLength, encoding) → {string}

Converts the given binary data to the string of the binary data.

Parameters:
Name Type Description
data DataView

the binary data to decode.

byteOffset number

The start index of text data in the data.

byteLength number

The length of text data in the data.

encoding string

The encoding type.

Source:
Returns:

Decoded string data.

Type
string

encode(text, encoding) → {DataView}

Converts the given string to the binary data of the string.

Parameters:
Name Type Description
text string

The text to encode.

encoding string

The encoding type to encode.

Source:
Returns:

Encoded binary data.

Type
DataView

encodingExists(value) → {boolean}

Checks whether the given string is a valid encoding type or not.

Parameters:
Name Type Description
value any

The value to check.

Source:
Returns:

true if the value is a valid encoding type.

Type
boolean