[Gambas-user] Bug or bad use of gb.net.curl?

Benoit Minisini gambas at ...1...
Thu Mar 29 14:46:34 CEST 2007


On mercredi 21 février 2007, Lorenzo Tejera wrote:
> I'm using the net.curl componente, but I have a problem that I can't
> resolv. I'm doing an application that retreive some .wma files from a
> specific web, but when I stored the file appears two bytes more that not
> belong to the file in the head of the file. But I did some probes and only
> occurs when I use the funcion Lof to define the size of the buffer I must
> to read. If lof is not use the head of file is saved perfect, but I not get
> all the buffer and the file is incompleted.
>
> For example:
>
> This is what I obtiain:
>
> „¥GIF89a
>
> But it should be:
>
> GIF89a
>
> The rest of file is saved perfect.
>
> This is the lines of code I used to read httpclient and write to a file in
> hard disk.
>
> IF Lof(HttpDescarga) THEN
> READ #HttpDescarga, Buffer, Lof(HttpDescarga)

I think I understand: Lof() returns the number of bytes you can read from the 
stream. So after this line, Lof(HttpDescarga) will return 0.

> WRITE #gFichero, Buffer, Lof(HttpDescarga)

And so in this line, the third argument of WRITE is zero, and so Gambas will 
write the length of the string before writing its contents (this is the two 
bytes before 'GIF89a').

You should do something like that:

DO
  HttpLen = Lof(HttpDescarga)
  IF HttpLen THEN
    READ #HttpDescarga, Buffer, HttpLen
    WRITE #gFichero, Buffer, HttpLen
  ELSE
    BREAK
  ENDIF
LOOP

> END IF

Regards,

-- 
Benoit Minisini




More information about the User mailing list