arrayBuffer 에 저장된 byte 들을 UTF-8/UTF-16 으로 인코딩된 string 으로 해석하여 돌려줍니다. FileStream.read() 의 구현에 사용됩니다. 직접 사용하기 보다는 FileStream 을 생성하는 것을 권장합니다.

Syntax

toUtf8String(arrayBuffer, byteOffset, length);
toUtf16String(arrayBuffer, byteOffset, length);
toShiftJisString(arrayBuffer, byteOffset, length);

Parameters

arrayBuffer

byte 를 읽을 ArrayBuffer .

byteOffset

ArrayBuffer 에서 읽을 첫번째 byte 의 인덱스(index).

length

읽을 byte 의 길이

Return value

string

Example

function example() {
    const float    = new Uint8Array([0xd8, 0xf, 0x49, 0x40]).buffer;
    const double   = new Uint8Array([0, 0, 0, 0, 0xfb, 0x21, 0x9, 0x40]).buffer;
    const utf8str  = new Uint8Array([0xec, 0x95, 0x88, 0xeb, 0x87, 0xbd, 0]).buffer;
    const utf16str = new Uint8Array([0x52, 0xD8, 0x62, 0xDF]).buffer;
    
    const int8  = new Uint8Array([0xfe]).buffer;
    const uint8 = new Uint8Array([0xfe]).buffer;

    const int16  = new Uint8Array([0xf0, 0xff]).buffer;
    const uint16 = new Uint8Array([0xf0, 0xff]).buffer;

    const int32  = new Uint8Array([0xf0, 0xff, 0xff, 0xff]).buffer;
    const uint32 = new Uint8Array([0xf0, 0xff, 0xff, 0xff]).buffer;

    const int64  = new Uint8Array([0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]).buffer;
    const uint64 = new Uint8Array([0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]).buffer;

    console.log(toFloat(float));                                  // 3.141592025756836
    console.log(toDouble(double));                                // 3.141592025756836
    console.log(toUtf8String(utf8str, 0, utf8str.byteLength));    // 안뇽
    console.log(toUtf16String(utf16str, 0, utf16str.byteLength)); // 𤭢

    console.log(toInt8(int8));   // -2
    console.log(toUint8(uint8)); // 254

    console.log(toInt16(int16));   // -16
    console.log(toUint16(uint16)); // 65520

    console.log(toInt32(int32));   // -16
    console.log(toUint32(uint32)); // 4294967280

    console.log(toInt64(int64));   // -16n
    console.log(toUint64(uint64)); // 18446744073709551600n
}