This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |