MCPcopy Create free account
hub / github.com/denoland/std / decodeBase32

Function decodeBase32

http/unstable_structured_fields_test.ts:711–731  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

709const BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
710
711function decodeBase32(input: string): Uint8Array {
712 // Remove padding
713 input = input.replace(/=+$/, "").toUpperCase();
714 if (input.length === 0) return new Uint8Array(0);
715
716 const output: number[] = [];
717 let bits = 0;
718 let value = 0;
719
720 for (const char of input) {
721 const idx = BASE32_ALPHABET.indexOf(char);
722 if (idx === -1) throw new Error(`Invalid base32 character: ${char}`);
723 value = (value << 5) | idx;
724 bits += 5;
725 if (bits >= 8) {
726 bits -= 8;
727 output.push((value >> bits) & 0xff);
728 }
729 }
730 return new Uint8Array(output);
731}
732
733// Convert test suite expected value to our internal format
734// deno-lint-ignore no-explicit-any

Callers 1

convertExpectedBareItemFunction · 0.70

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected