LZ77 finds sequences of bytes that occur multiple times, and stores them only once:
LZ77.encode (Encode.encode (Encode.string "aaaaa"))
--> [ Literal 97, Pointer 4 1 ]The character a occurs 5 times, which is encoded as "the byte 97; go back 1 position and read 4 bytes there, putting them onto the end of the stream".
Note that the pointer tries to read 4 bytes, even though the output stream at that point only has length 1. This is fine: the elements are copied over one by one.
The codes
distance positions back and read length bytes. put the read bytes at the end of the output stream.Encode using the LZ77 encoding, with additional options.
Pointer can jump. A bigger window size gives better compression, but requires more data in memory.
That is almost never a problem nowadays though, so encode uses the maximum window size that LZ77 supports.Maximum size of a sliding window.
Encode using the LZ77 encoding