@cloudpss/ubjson
Version:
Opinionated UBJSON encoder/decoder for CloudPSS.
11 lines (10 loc) • 399 B
text/typescript
/** 支持的数据转为 Uint8Array */
export function toUint8Array(data: BufferSource): Uint8Array {
if (data == null || typeof data != 'object' || typeof data.byteLength != 'number') {
throw new TypeError('Invalid data');
}
if (!ArrayBuffer.isView(data)) {
return new Uint8Array(data);
}
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}