DFL, Progress Bar, and how to use it against a download

Lester L. Martin II Lester at ewam-associates.com
Sun Nov 18 03:08:48 PST 2007


Lester L. Martin II Wrote:

> Chris Miller Wrote:
> 
> > On Sat, 17 Nov 2007 11:11:38 -0500, Lester L. Martin II  
> > <Lester at ewam-associates.com> wrote:
> > 
> > > Lester L. Martin II Wrote:
> > >
> > >> Hello,
> > >> I could probably figure this out if I actually put some time to it but  
> > >> I seldom have enough time to think such through perfectly.
> > >> My question is how do you use DFL's progress bar with Tango's HTTPget  
> > >> and display a progress.
> > >> If anyone has an answer I would love to see it as this is going to be  
> > >> needed really bad in the project I'm working on(maybe others will join)  
> > >> and I'd rather not spend a whole day implementing this perfectly when  
> > >> their is already a way to do it so I can put my attention to more  
> > >> important things.
> > >>
> > >> Thanks in advance,
> > >> Lester L. Martin II
> > >
> > > Or tango's httpclient; I think I know how I'm just not sure that when  
> > > you call read with the delegate and length will read call the delegate  
> > > and supply the array of specified length and do so until it gets through  
> > > or will it read that length and stop and wait for you to call read again.
> > > If anyone has an example with HttpClient and the delegate read thing I  
> > > described I'd love to see it.  If it does require to call read more than  
> > > once, how do you check that you have read everything and there is  
> > > nothing more to read.
> > >
> > > Lester L. Martin II
> > >
> > 
> > Not sure about Tango, but with the DFL ProgressBar, you can set the  
> > 'maximum' property to the file size and update the 'value' property to the  
> > current size downloaded.
> 
> So are you using phobos or your own socket implementation.
> How would you use the socket for a HTTP connection if you are using sockets in you example.
> 
> Lester L. Martin II
> 

Wait now I think I see a way.

auto pb = new ProgressBar();
auto client = new HttpClient(HttpClient.Get, "http://www.yahoo.com");
client.open();
if (client.isResponseOK)
           {
           // extract content length
           auto length = client.getResponseHeaders.getInt (HttpHeader.ContentLength, uint.max);
pb.maximum(length);
client.read(&sink, length);
}

then the sink
void sink(void[] content)
{
//assuming file is inside class;
file.write(content);
pb.value = content.length;
}

is there somewhere I messed up( such as I don't know if you can get the size of a void array, or should I have a loop that gets it maybe 10 bytes(whatever it measures by) at a time).

Thanks for all your help.
Lester L. Martin II




More information about the Digitalmars-d-learn mailing list