14 lines
429 B
TypeScript
14 lines
429 B
TypeScript
/**
|
|
* Convert big-endian u32 to native JavaScript number.
|
|
*/
|
|
export function uint_bytes_to_num(value: Uint8Array): number {
|
|
if (value.length != 4) { throw new Error("can't convert non 4-byte integer"); }
|
|
const data_view = new DataView(value.buffer);
|
|
return data_view.getUint32(0, false);
|
|
}
|
|
|
|
export function utf8_decode(value: Uint8Array): string {
|
|
const decoder = new TextDecoder("utf-8");
|
|
return decoder.decode(value);
|
|
}
|