This project has moved and is read-only. For the latest updates, please go here.

Gzip compression - Steaming API - How?

Jul 1, 2013 at 10:29 AM

I listen to the Tweet Steam using Linq2Twitter filter. The code runs fine (so far 2 days without interruptions), but twitter also sends quite a lot of data.

I read that twitter enabled gzip on the steaming api in 2012. How can i exploit this in Linq2Twitter? I cannot seem to find any information on the matter or any property I can set. I have found auth.UseCompression but that does not seem to do anything?

The important parts of my code is:
  var auth = new SingleUserAuthorizer
                Credentials = new InMemoryCredentials
                    ConsumerKey = "x",
                    ConsumerSecret = "y",
                    OAuthToken = "z",
                    AccessToken = "v",

            auth.UseCompression = true;
            auth.UserAgent = "Linq2twitter 1.0";

                using (var twitterCtx = new TwitterContext(auth))
                    twitterCtx.Log = logTextWriter;
                    (from strm in twitterCtx.Streaming 
where strm.Type == StreamingType.Filter && strm.Locations == "-6,50.45,0.43,58" 
select strm).StreamingCallback(strm =>
                        processTweet(strm); //Use a JSON parser

                        if (stop)
The steam is not zipped, because I can read it directly in the parser without using any Gzip c# library. Is it possible to enable Gzip compression in Linq2twitter as described [Here]?(
Jul 2, 2013 at 11:33 PM

You'll always receive an uncompressed response in StreamingCallback because LinqToTwitter takes care of compressing requests and decompressing responses. I recall specifically working on this issue a few months back. I was using Fiddler2 to verify that the stream was compressed. You are correct that the UseCompression must be set to true to enable compression. Are you inspecting the stream via Fiddler2 or some other tool, or were you thinking that the StreamingCallback response would give you compressed data?

Jul 3, 2013 at 8:27 AM
Hi Joe.

I just assumed that L2T didn't handle compression so when I was still able to still read the stream's content I didn't think the stream was compressed. If it's all handled for me then that's excellent :)

I used Fiddler to check and it returned gzip in most cases. However, it seems like sometimes it is not used. Is there anywhere in the code using L2T that I can check whether Twitter send the stream in compressed mode? (and reconnect if it doesn't)

Best regards
Morten Gryning