Alon Rew
Alon Rew

Reputation: 85

Websocket sharing LZ77 Sliding window - with context takeover

I am going over the permessage-deflate rfc and I don't understand the part about 'sharing LZ77 Sliding window' (section 7.2.3.2.)

It says that If the "agreed parameters" did not contain the "client_no_context_takeover" extension parameter, the client can compress the payload of the next message into less bytes by referencing the history in the LZ77 sliding window.

How will the server know if the client used the same sliding window or used a new one? How will the server decompress the message? How can I use Zlib(or any other lib) to compress/decompress a message like this?

Upvotes: 1

Views: 523

Answers (1)

Mark Adler
Mark Adler

Reputation: 112374

If client_no_context_takeover is agreed to, then always assume that the next message can use the previous sliding window contents. If it doesn't then the previous window will not be referenced and no harm is done. You must continue to assume that any compressed message can refer to the sliding window and update the sliding window, since the third message could refer to the first and second messages in the sliding window, even if the second message didn't refer to the first.

To decompress, maintain a zlib inflate instance and continue to feed it compressed data. The inflate instance will maintain the sliding window for you. Append 00 00 ff ff to each compressed message and feed that to inflate(). Each subsequent message will use the sliding window built of previous messages, if referred to in the compressed data.

Upvotes: 2

Related Questions