Skip to content
On this page

Bytes to String Converter

Class NameUint8ArrayToString
Input TypeUint8Array
Output Typestring
PurposeThis class helps us to convert bytes to string

Bytes are represented as Uint8Array

Class Signature

ts
class Uint8ArrayToString implements TransformerFunction<Uint8Array, string> {
  //...
}
class Uint8ArrayToString implements TransformerFunction<Uint8Array, string> {
  //...
}

Usage

ts
// Hello World! encoded as Uint8Array
const input = Uint8Array.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]);

const result = new Uint8ArrayToString().convert(input);
expect(result).toEqual('Hello World!'); // ✅
// Hello World! encoded as Uint8Array
const input = Uint8Array.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]);

const result = new Uint8ArrayToString().convert(input);
expect(result).toEqual('Hello World!'); // ✅

Released under the MIT License.