Nodejs String from Ascii85 fromAscii85()

Here you can find the source of fromAscii85()

Method Source Code

String.prototype.fromAscii85 = function() {
  var str = this.slice(2, -2).replace(/\s/g, ''), result = ''
  while (str.length) {
    if (str[0] == 'z') {
      result += '\u0000\u0000\u0000\u0000'
      str = str.substr(1)/*  ww  w . j  a v a2s  .co  m*/
    } else {
      let num = 0, j = 5, i = 4
      while (j--) {
        num += (((str.charCodeAt(4-j) || 117)-33)*Math.pow(85, j)) || 0
      }
      while (i-- && str.length > 4-i) {
        result += String.fromCharCode((num/Math.pow(2, 8*i))%256)
      }
      str = str.substr(5)
    }
  }
  return result
}

Related

  1. fromAscii85()
    String.prototype.fromAscii85 = function() {
      var ret = "";
      var str = this.replace(/\s+/g, "").replace("z", "!!!!!").slice(2, -2);
      for(var i=0; i<str.length; i+=5){
        var deficit = Math.max(0, 5+i-str.length);
        var nnn = 0;
        for(var j=0; j<5; j++){
          nnn = nnn*85 + (str.charCodeAt(i+j) || 117) - 33;
        var codes = [];
        for(var j=0; j<4; j++){
          codes.push(nnn%256);
          nnn = nnn/256 | 0;
        codes.reverse();
        var chunk = String.fromCharCode.apply(undefined, codes).slice(0, 4-deficit);
        ret+= chunk;
      return ret;
    
  2. fromAscii85()
    String.prototype.fromAscii85 = function() {
      var str = this.slice(2, -2).replace(/z/g, '!!!!!').replace(/\s/g, '');
      var decoded = '';
      for(var i = 0, len = str.length; i < len; i+=5) {
        var n = 0;
        var us = 0;
        for(var j = 4; j >= 0; j--) {
          var c = str[j+i] || (us++, 'u'),
              code = c.charCodeAt(0) - 33;
    ...
    
  3. fromAscii85()
    String.prototype.fromAscii85 = function() {
        console.log(this)
        let pad = 'u', addnum = 0, s = this.substring(2, this.length - 2).replace(/\s/g, ''), str = '', res = '';
        for (let i = 0; i < s.length; i++)
            str += s[i] === 'z' ? '!!!!!' : s[i];
        while (str.length % 5 !== 0)
            str += pad;
            addnum ++;
    ...