basant307/AI_Governance_Project
048
1const encoder = new TextEncoder()2 3export function encodeBuffer(text: string): Uint8Array {4 return encoder.encode(text)5}6 7export function decodeBuffer(buffer: ArrayBuffer, encoding?: string): string {8 const decoder = new TextDecoder(encoding)9 return decoder.decode(buffer)10}11 12/**13 * Create an `ArrayBuffer` from the given `Uint8Array`.14 * Takes the byte offset into account to produce the right buffer15 * in the case when the buffer is bigger than the data view.16 */17export function toArrayBuffer(array: Uint8Array): ArrayBuffer {18 return array.buffer.slice(19 array.byteOffset,20 array.byteOffset + array.byteLength21 )22}23 