Add logging, closes #2
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
import {Result} from 'result'
|
||||
import logger from 'log'
|
||||
|
||||
const log = logger('misc')
|
||||
|
||||
export function a2str(buf: Uint8Array) : string {
|
||||
log.debug('a2str')
|
||||
// @ts-ignore
|
||||
return String.fromCharCode.apply(null, buf)
|
||||
}
|
||||
export function str2a(str: string) : Uint8Array {
|
||||
log.debug('str2a')
|
||||
|
||||
const buf = new Uint8Array(str.length)
|
||||
|
||||
for (let i= 0, strLen = str.length; i < strLen; i++) {
|
||||
@@ -15,12 +21,18 @@ export function str2a(str: string) : Uint8Array {
|
||||
}
|
||||
|
||||
export function a2b64(buf: Uint8Array) : string {
|
||||
log.debug('a2b64')
|
||||
return btoa(a2str(buf))
|
||||
}
|
||||
export function b642a(b64: string) : Result<Uint8Array> {
|
||||
log.debug('b642a')
|
||||
|
||||
try {
|
||||
return Result.ok(str2a(atob(b64)))
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
log.warn('b64 decode failed')
|
||||
log.debug(`error : ${e}`)
|
||||
}
|
||||
|
||||
return Result.error([])
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"files": ["index.ts"],
|
||||
|
||||
"dependencies": {
|
||||
"log": "git+git@git.pband.ch:typescript/log",
|
||||
"result": "git+git@git.pband.ch/typescript/result"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Reference in New Issue
Block a user