Skip to content

Instantly share code, notes, and snippets.

View sanrai's full-sized avatar

Sanjay Rai sanrai

View GitHub Profile
// Base64 encoding function
function base64Encode(uint8Array) {
let binary = '';
const len = uint8Array.length;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(uint8Array[i]);
}
return btoa(binary);
}
// URL-safe character set for Base85 encoding (now with 85 characters)
const URL_SAFE_CHARS = [
// Digits (10)
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
// Uppercase letters (26)
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
// Lowercase letters (26, including 'z')
// Base85 encoding function using BigInt
function base85Encode(bytes) {
const ASCII85_CHARS = Array.from({ length: 85 }, (_, i) => String.fromCharCode(i + 33));
let output = '';
let i = 0;
while (i < bytes.length) {
let chunkSize = Math.min(4, bytes.length - i);
let value = BigInt(0);
for (let j = 0; j < chunkSize; j++) {
// Base85 encoding function using BigInt
function base85Encode(bytes) {
const ASCII85_CHARS = Array.from({ length: 85 }, (_, i) => String.fromCharCode(i + 33));
let output = '';
let i = 0;
while (i < bytes.length) {
let chunkSize = Math.min(4, bytes.length - i);
let value = BigInt(0);
for (let j = 0; j < chunkSize; j++) {
function base85Encode(input) {
const ASCII85_CHARS = Array.from({ length: 85 }, (_, i) => String.fromCharCode(i + 33));
const encoder = new TextEncoder();
const bytes = encoder.encode(input);
let output = '';
let i = 0;
while (i < bytes.length) {
let chunkSize = Math.min(4, bytes.length - i);
let value = 0;