import { rfc4648 } from "../../deps.ts";
const decoder: TextDecoder = new TextDecoder();const encoder: TextEncoder = new TextEncoder();
export function bytesToString(bytes: Uint8Array): string { return decoder.decode(bytes);}
export function stringToBytes(str: string): Uint8Array { return encoder.encode(str);}
export function stringLengthInBytes(str: string): number { return stringToBytes(str).length;}
export function concatBytes(a: Uint8Array, b: Uint8Array): Uint8Array { if (!b || b.length === 0) return a; if (!a || a.length === 0) return b;
var c = new Uint8Array(a.length + b.length); c.set(a); c.set(b, a.length);
return c;}
export function b64StringToBytes(b64string: string): Uint8Array { return rfc4648.base64.parse(b64string);}
export function isBytes(bytes: any): bytes is Uint8Array { return bytes?.constructor?.name === "Uint8Array"; }
export function isBuffer(buf: any): boolean { return buf?.constructor?.name === "Buffer"; }
export function identifyBufOrBytes(bufOrBytes: any | Uint8Array): string { if (isBytes(bufOrBytes)) return "bytes"; if (isBuffer(bufOrBytes)) return "buffer"; return "?";}