LZ77 compression algorithm
See Ziv, Jacob; Lempel, Abraham (May 1977). "A Universal Algorithm for Sequential Data Compression". IEEE Transactions on Information Theory 23 (3): 337343.
Very naive implementation, do not expect it to be very efficient.