Posts

Showing posts from January, 2016

Processing a downloaded text file while it's downloading

I've had a job where I had to download some huge text files and I thought it interesting to process them while they are downloading, instead of waiting until the download was finished. (Time was very important.) Ultimately, the client changed his mind and wanted the whole thing downloaded first but I thought this was an interesting code fragment to save for later. When it comes to "do real-time stuff" I use the Rx-Main NuGet package . The interface is simple: public interface Downloader { /// <summary> /// Downloads a file from the given URL and returns it line by line. /// </summary> /// <param name="url">The URL of the file to be downloaded.</param> /// <returns>The lines from the downloaded file, as a stream.</returns> IObservable<string> Download(string url); } The only noteworthy thing about the implementation is the automatic decompression; using that property sends the appropr