curl-library
RE: Problem with binary data
Date: Fri, 31 Oct 2003 12:36:15 -0500
Thanx guys for I surely do not feel lost anymore, with the support am
receiving. Here is a snippet of the code am running on a solaris box. I have
removed the rest of the code thinking it might be a little difficult for you
to read it.
1. I call the curl easy option to register the callback
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION,
VIPClient::WriteMemoryCallbackWrapper);
2. From my callback routine, I dump the data in a file as shown in the
function below
size_t VIPClient::WriteMemoryCallbackWrapper(void *buffer, size_t
size,size_t nmemb, void *stream)
{
FILE* fd=fopen("ImageFile.txt","a");
setvbuf(fd,NULL,_IONBF,0); /* Unbuffered mode for fwrite */
return fwrite(buffer, size, nmemb, fd);
}
3. Once done, I read the buffer in a character array and pass it on to a
function which strips of first 11 bytes. The first 11 bytes which is always
set to "|DELIMITER|" is a kind of header tag indicating the beginning of
binary data.
FILE* fd=fopen("ImageFile.txt","r");
if(!fd)
{
/* Log error. */
}
char *cptrServerResponse = new char [BUFF];
int NumberOfBytesForImages=fread(cptrServerResponse,
sizeof(char),BUFF_SWAP,fd);
cout<<endl<<"Number of bytes read "<<NumberOfBytesForImages;
cptrServerResponse[NumberOfBytesForImages]='\0';
fclose(fd);
}
/* This function strips off the first 11 bytes tag "|DELIMITER|" */
int ProcessXmlStat = ProcessServerResponse(cptrServerResponse);
It just struck my mind. Could there be a problem because am trying to read
from the file in a character array which actually truncates one of the bytes
thus corrupting the data. (Just a wild guess!)
Gracias,
amit
-----Original Message-----
From: Linus Nielsen Feltzing [mailto:linus_at_haxx.se]
Sent: Friday, October 31, 2003 12:07 PM
To: curl-library_at_lists.sourceforge.net
Subject: Re: Problem with binary data
Sharma, Amit wrote:
> If there is any problem in my callback, does anybody has some
> suggestions on debugging tips for something for this.
You could of course let us see the code. Could you describe a little
better how the data is garbled?
Linus
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. Does
SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
Received on 2003-10-31