This commit is contained in:
2024-05-21 15:48:27 +02:00
parent cb6aa2e026
commit 0b21e3a246
+9 -1
View File
@@ -1,4 +1,7 @@
import {Result} from 'result'
import logger from 'log'
const log = logger('misc')
export function a2str(buf: Uint8Array) : string {
// @ts-ignore
@@ -18,9 +21,14 @@ export function a2b64(buf: Uint8Array) : string {
return btoa(a2str(buf))
}
export function b642a(b64: string) : Result<Uint8Array> {
log.trace('b642a')
try {
return Result.ok(str2a(atob(b64)))
} catch (e) {}
} catch (e) {
log.warn('b64 decode failed')
log.debug(`error : ${e}`)
}
return Result.error([])
}