For those of you who would like a loquacious version of Dave Brown's answer (reverse engineered from his answer and tested):
function encode_ascii85(sSource) {
var sSuffix, iStringLength, f;
var charArray = [];
if (!/[^\x00-\xFF]/.test(sSource)) {
[sSource, sSuffix, iStringLength] = initForLoop(sSource);
for (var iIndex = 0; iStringLength > iIndex; iIndex += 4) {
f = (sSource.charCodeAt(iIndex) << 24) + (sSource.charCodeAt(iIndex + 1) << 16);
f = f + (sSource.charCodeAt(iIndex + 2) << 8) + sSource.charCodeAt(iIndex + 3);
appendNextChar(f, charArray);
}
(function truncate(oArray, b) {
for (var m = b.length; m > 0; m--) oArray.pop();
})(charArray, sSuffix);
return "<~" + String.fromCharCode.apply(String, charArray) + "~>";
} else {
// Error Handling
}
function initForLoop(a) {
var sSuffix = "\x00\x00\x00\x00".slice(a.length % 4 || 4);
return [a += sSuffix, sSuffix, a.length];
}
function appendNextChar(f, oArray) {
if (f === 0) {
oArray.push(122);
} else {
var g, h, i, j, k;
k = f % 85, f = (f - k) / 85;
j = f % 85, f = (f - j) / 85;
i = f % 85, f = (f - i) / 85;
h = f % 85, f = (f - h) / 85;
g = f % 85;
oArray.push(g + 33, h + 33, i + 33, j + 33, k + 33);
}
}
}
function decode_ascii85(sSource) {
var sSuffix, d, iStringLength;
var charArray = [];
if ("<~" === sSource.slice(0, 2) && "~>" === sSource.slice(-2)) {
sSource = initForLoop(sSource);
for (var iIndex = 0; iStringLength > iIndex; iIndex += 5) {
var x = "charCodeAt";
var w = 255;
d = 85 * 85 * 85 * 85 * (sSource[x](iIndex) - 33) + 85 * 85 * 85 * (sSource[x](iIndex + 1) - 33);
d = d + 85 * 85 * (sSource[x](iIndex + 2) - 33) + 85 * (sSource[x](iIndex + 3) - 33) + (sSource[x](iIndex + 4) - 33);
charArray.push(w & d >> 24, w & d >> 16, w & d >> 8, w & d);
}
(function truncate(oArray, b) {
for (var m = b.length; m > 0; m--) oArray.pop();
})(charArray, sSuffix);
return String.fromCharCode.apply(String, charArray);
} else {
// Error Handling
}
function initForLoop(a) {
var z = "replace",
y = "slice";
a = a[y](2, -2)[z](/\s/g, "")[z]("z", "!!!!!");
sSuffix = "uuuuu" [y](a.length % 5 || 5);
a += sSuffix;
iStringLength = a.length;
return a;
}
}