UNPKG

tdlib-native

Version:

🚀 Telegram TDLib native nodejs wrapper

26 lines (25 loc) • 968 B
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; function encode(bytes) { let result = ""; let index; for (index = 2; index < bytes.length; index += 3) { result += alphabet[bytes[index - 2] >> 2]; result += alphabet[(bytes[index - 2] & 3) << 4 | bytes[index - 1] >> 4]; result += alphabet[(bytes[index - 1] & 15) << 2 | bytes[index] >> 6]; result += alphabet[bytes[index] & 63]; } if (index === bytes.length + 1) { result += alphabet[bytes[index - 2] >> 2]; result += alphabet[(bytes[index - 2] & 3) << 4]; result += "=="; } else if (index === bytes.length) { result += alphabet[bytes[index - 2] >> 2]; result += alphabet[(bytes[index - 2] & 3) << 4 | bytes[index - 1] >> 4]; result += alphabet[(bytes[index - 1] & 15) << 2]; result += "="; } return result; } exports.encode = encode;