cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Use memory to ftp upload large image and got a bad performance

From: huafeng wu <wuhuafeng_at_gmail.com>
Date: Fri, 24 Apr 2009 21:01:23 +0800

Hello,
I try to modify the callback function. but at this time the ftp server get
this file with wrong format and can not open it.
So I open this upload file with hex and if the BUFFER_SIZE is 100, I find
the first byte is right. the other 99 bytes are wrong.
Can you tell me how to modify this function. And how to set the third
parameter - nmemb
Thanks

#define BUFFER_SIZE 100
static size_t ReadMemoryCallback(void *ptr, size_t size, size_t nmemb, void
*pMem)
{
    struct MemoryStruct *pRead = (struct MemoryStruct *)pMem;

    if ((size * nmemb) < 1)
        return 0;

    if (pRead->size > BUFFER_SIZE)
    {
        *(char *)ptr = pRead->memory[0];
        pRead->memory += BUFFER_SIZE;
        pRead->size -= BUFFER_SIZE;
        return BUFFER_SIZE;
    }
    else
    {
        size_t size_left = pRead->size;

        *(char *)ptr = pRead->memory[0];
        pRead->memory += pRead->size;
        pRead->size = 0;
        return(size_left);
    }
    return 0; // no more data left to deliver
}

2009/4/24 Daniel Stenberg <daniel_at_haxx.se>

> On Fri, 24 Apr 2009, huafeng wu wrote:
>
> if (pRead->size)
>> {
>> *(char *)ptr = pRead->memory[0]; // copy one single byte
>> pRead->memory++; // advance pointer
>> pRead->size--; // less data left */
>> return 1;
>> }
>>
>
> This is the reason. It returns one byte at a time. You should rewrite it to
> fill as much as possible of the buffer in each invoke.
>
> --
>
> / daniel.haxx.se
>
Received on 2009-04-24