You're right. It wouldn't have worked without the 0x0000ffff. However, the
test data was being dumped from an existing codebase handling websockets
that was already appending that to each message.

For reference (and since other people have asked me for it), here's the
entire sample code with a link to the test file I used:
https://gist.github.com/ajkeeton/87352777b8f458b05f363fe8cd73803c

On Wed, Jul 20, 2016 at 11:51 AM, joetsai via golang-nuts <
golang-nuts@googlegroups.com> wrote:

>     // Unsplit into a single contiguous stream
>>     for _, msg := range messages {
>>         // msg in this case is a single websockets message
>>         compData.Write(msg)
>>     }
>>     decompressed, err := ioutil.ReadAll(deflater)
>>     fmt.Printf("Err: %v. Decompressed:\n%s\n\n", err,
>> hex.Dump(decompressed[0:len(decompressed)]))
>
> I'm actually surprised that the above logic works with all the messages
> concatenated. The "permessage-deflate" scheme for websockets uses the same
> mechanism as RFC 1979, which dictates that the transmitter always calls
> flate.Writer.Flush and that the framing protocol must remove the 0x0000ffff
> marker (see RFC 1979, section 2.1, on Data) that comes at the end of a
> flushed DEFLATE block. Without manually reinserting this 0x0000ffff marker,
> it is highly unlikely that this represents a valid DEFLATE stream.
>
> With that said, it is possible to actually use the standard library
> compress/flate to decompress each websocket message, message-by-message.
>
> See this following example:
> https://play.golang.org/p/TqUm4785B2
>
> On Monday, July 18, 2016 at 8:00:51 AM UTC-7, A Keeton wrote:
>>
>> I initially tried that. Turns out deflate needs to maintain the same
>> sliding window across messages depending on whether or not context takeover
>> is being used - https://tools.ietf.org/html/rfc7692#section-7
>>
>> On Saturday, July 16, 2016 at 2:04:59 AM UTC-4, Tamás Gulácsi wrote:
>>>
>>> What if you create a new deflater for each message? And use a new
>>> Buffer, too! Maybe deflater reads too much into the followings.
>>> If this works, you can look into why Reset is not enough.
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/-LqYo5PpHTM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to