MCPcopy Create free account
hub / github.com/Effect-TS/effect / base64EncodeUint8Array

Function base64EncodeUint8Array

packages/effect/src/Encoding.ts:504–531  ·  view source on GitHub ↗
(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

502// Base64 internals
503
504const base64EncodeUint8Array = (bytes: Uint8Array) => {
505 const length = bytes.length
506
507 let result = ""
508 let i: number
509
510 for (i = 2; i < length; i += 3) {
511 result += base64abc[bytes[i - 2] >> 2]
512 result += base64abc[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)]
513 result += base64abc[((bytes[i - 1] & 0x0f) << 2) | (bytes[i] >> 6)]
514 result += base64abc[bytes[i] & 0x3f]
515 }
516
517 if (i === length + 1) {
518 result += base64abc[bytes[i - 2] >> 2]
519 result += base64abc[(bytes[i - 2] & 0x03) << 4]
520 result += "=="
521 }
522
523 if (i === length) {
524 result += base64abc[bytes[i - 2] >> 2]
525 result += base64abc[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)]
526 result += base64abc[(bytes[i - 1] & 0x0f) << 2]
527 result += "="
528 }
529
530 return result
531}
532
533function getBase64Code(charCode: number) {
534 if (charCode >= base64codes.length) {

Callers 2

encodeBase64Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected