views:

74

answers:

1

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 inputting 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?

+1  A: 

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.

svenningsson
You answer is something that looks like "use sources, Luk". This is what i didn't want to do myself. I accept you answer, but putting -1 because, i still have to look through sources. little later I'll (maybe) post here what I've searched.
Vasiliy Stavenko
But given your vague description of the problem it's not easy to show exactly how to do it. As I said, if you give some more concrete details it would be possible to give a more helpful answer.
svenningsson