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

Function decode

encoding/_common16.ts:46–66  ·  view source on GitHub ↗
(
  buffer: Uint8Array_,
  i: number,
  o: number,
  alphabet: Uint8Array,
)

Source from the content-addressed store, hash-verified

44}
45
46export function decode(
47 buffer: Uint8Array_,
48 i: number,
49 o: number,
50 alphabet: Uint8Array,
51): number {
52 if ((buffer.length - o) % 2 === 1) {
53 throw new RangeError(
54 `Cannot decode input as hex: Length (${
55 buffer.length - o
56 }) must be divisible by 2`,
57 );
58 }
59
60 i += 1;
61 for (; i < buffer.length; i += 2) {
62 buffer[o++] = (getByte(buffer[i - 1]!, alphabet) << 4) |
63 getByte(buffer[i]!, alphabet);
64 }
65 return o;
66}
67
68function getByte(char: number, alphabet: Uint8Array): number {
69 const byte = alphabet[char] ?? 16;

Callers 15

transformMethod · 0.90
flushMethod · 0.90
transformMethod · 0.90
flushMethod · 0.90
transformMethod · 0.90
flushMethod · 0.90
transformMethod · 0.90
flushMethod · 0.90
decodeHexFunction · 0.90
decodeBase64Function · 0.90
decodeHexFunction · 0.90
decodeBase32Function · 0.90

Calls 1

getByteFunction · 0.70

Tested by

no test coverage detected