mramine364

lz77 decompression

Jun 25th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function lz77_decompress(input, dictlen){
  2.     let output="", drl=0, dl=dictlen;
  3.     for(let i=0; i<input.length; i++){
  4.         if( input[i].length==0 ){
  5.             output+=input[i].char;
  6.         }else{
  7.             let j=drl-dl+input[i].index, k=j;
  8.             let l2=input[i].length+input[i].index-Math.max(0, dl-drl),
  9.                 len=drl-dl+Math.min(dl, l2);
  10.             while( j<len ){
  11.                 output+=output[j];
  12.                 j++;
  13.             }
  14.             while( j<l2 ){
  15.                 output+=output[k];
  16.                 k++;
  17.                 j++;
  18.             }
  19.             output+=input[i].char;
  20.         }
  21.         drl+=input[i].length+1;
  22.     }
  23.     return output;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment