From b46bd6048ebe1b2629f744418778ca57a113c6fc Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 8 Sep 2023 08:41:52 -0400 Subject: [PATCH] refactor: move b64ToBuf from libweb --- src/util.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index 461da81..a4c3c47 100644 --- a/src/util.ts +++ b/src/util.ts @@ -115,4 +115,9 @@ function encodeU64(num: bigint): [Uint8Array, Err] { return [encoded, null]; } -export { objAsString, addContextToErr, encodeU64, decodeU64 }; +function bufToB64(buf: Uint8Array): string { + const b64Str = btoa(String.fromCharCode(...buf)); + return b64Str.replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", ""); +} + +export { objAsString, addContextToErr, encodeU64, decodeU64, bufToB64 };