102
rated 0 times
[
103]
[
1]
/ answers: 1 / hits: 18703
/ 14 Years ago, sun, march 20, 2011, 12:00:00
This JavaScript function takes an array of numbers (in the range 0-255) and converts to a base64-encoded string, then breaks long lines if necessary:
function encode(data)
{
var str = ;
for (var i = 0; i < data.length; i++)
str += String.fromCharCode(data[i]);
return btoa(str).split(/(.{75})/).join(n).replace(/n+/g, n).trim();
}
Can you do the same thing in less code? Can you do it so it runs faster? Portability no object, use brand new language features if you want, but 's gotta be in JavaScript.
More From » firefox-addon