开发者

haskell chuncked http reading

Here's the next practical question.

I want to download some big files from http server(database updates). This operation should block user UI, preventing him from inputti开发者_StackOverflow中文版ng data. SO the problem is to show user progress bar, which will tell him how much is it still to wait.

In python, request objects open file-like object. I have read it by chucks and reported to GUI by callback functions.

How to implement the same in haskell? how to get current downloaded size and report it?


In Haskell you would do it similarly to the python version but the details depend on the GUI library that you use.

There are some options regarding how you detect how much of the input that has arrived. One way is to use lazy IO. Then you typically get a string as a result which is constructed lazily as the data arrives. You can then write IO functions which traverses the list and updates the UI as it goes along. This can be a quite convenient method, but lazy IO tend to be very fragile so use it with care.

The other option is to use some interface which provides access to the chunks as they arrive. I don't have any personal experience with such a library but the HTTP library seems to support that, in the Base module.

For tracking the progress there is a nice module for that in the MissingH library: Data.Progress.Tracker.

If you give more details about your particular scenario it would be possible to comment further.

Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜