MCPcopy Create free account
hub / github.com/cloudflare/computer / decodeBase32

Function decodeBase32

packages/computer/src/assets/base32.ts:58–75  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

56// that don't fill a byte are discarded, matching the encoder's
57// zero-padding of the final group.
58export function decodeBase32(text: string): Uint8Array {
59 const out: number[] = [];
60 let bits = 0;
61 let value = 0;
62 for (const char of text) {
63 const digit = DECODE.get(char);
64 if (digit === undefined) {
65 throw new Error(`decodeBase32: invalid character ${JSON.stringify(char)}`);
66 }
67 value = (value << 5) | digit;
68 bits += 5;
69 if (bits >= 8) {
70 bits -= 8;
71 out.push((value >>> bits) & 0xff);
72 }
73 }
74 return new Uint8Array(out);
75}
76
77// Generate a short random id: 16 random bytes (a UUID's worth of
78// entropy) Crockford base32-encoded into 26 lowercase characters.

Callers 1

base32.test.tsFile · 0.85

Calls 2

getMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected