cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curlpp mailing list Archives

Re: [cURLpp] Downloaded binary files are corrupted

From: Nazario Cipriani <NazarioCipriani_at_web.de>
Date: Fri, 17 Jun 2005 12:27:26 +0200

Hi All!

The problem with binary files seems won't stop.

I've got problems with binary files from any type.
It makes no difference if this is an image file, archive file or
something else...
Now I'm really wondering what am I making wrong?!?!?!

Does someone have any idea?

Thanks in advance!
Ragards, Nazario.

Jean-Philippe Barrette-LaPierre wrote:
> On May 14, 2005 07:22 am, Nazario Cipriani wrote:
>
>>Hi everybody.
>>
>>Seems like the problems with the binary files won't stop.
>>But I don't know if it's a problem due to wrong usage of the lib or not.
>>I think I'm doing all the right way...
>>
>
>
> Hi, I'm back from vacation. Have you resolved your problem?
>
>
>>Well the problem is, that downloaded binary files seems to be corrupted.
>>Now I'm wondering why this is so.
>>
>>This is the MemoryWriterClass I'm using (same as in post "Problems
>>downloading binary files to memory"):
>>
>> class WriterMemoryClass
>> {
>> public:
>> // Helper Class for reading result from remote host
>> WriterMemoryClass()
>> {
>> this->m_pBuffer = NULL;
>> this->m_pBuffer = (char*) malloc(MAX_FILE_LENGTH * sizeof(char));
>> this->m_Size = 0;
>> };
>> ~WriterMemoryClass()
>> {
>> if (this->m_pBuffer)
>> free(this->m_pBuffer);
>> };
>> static void* Realloc(void* ptr, size_t size)
>> {
>> if(ptr)
>> return realloc(ptr, size);
>> else
>> return malloc(size);
>> };
>> // Callback must be declared static, otherwise it won't link...
>> static size_t WriteMemoryCallback(char* ptr, size_t size, size_t
>>nmemb, void* data)
>> {
>> // Calculate the real size of the incoming buffer
>> size_t realsize = size * nmemb;
>>
>> // Cast the void* data pointer to WriterMemoryClass...
>> WriterMemoryClass* Memory = (WriterMemoryClass*) data;
>>
>> // (Re)Allocate memory for the buffer
>> Memory->m_pBuffer = (char*) Memory->Realloc(Memory->m_pBuffer,
>>Memory->m_Size + realsize + 1);
>>
>> // Test if Buffer is initialized correctly & copy memory
>> if (Memory->m_pBuffer)
>> {
>> memcpy(&(Memory->m_pBuffer[Memory->m_Size]), ptr, realsize);
>> Memory->m_Size += realsize;
>> Memory->m_pBuffer[Memory->m_Size] = 0;
>> }
>>
>> // return the real size of the buffer...
>> return realsize;
>> };
>>
>> // Public member vars
>> char* m_pBuffer;
>> size_t m_Size;
>> };
>>
>>For ASCII files all works fine.
>>But the same code doesn't seem to work for binary files.
>>
>>I've tried downloading a zip file from host with its original size of
>>5kB. After revceiving it with the class posted above I write the buffer
>>to disk with
>>
>> // Get the result...
>> char* Result = this->m_pConnection->GetResult();
>>
>> // Prepare the parameters for parsing...
>> std::stringbuf* Buffer = new std::stringbuf(Result);
>> std::istream* StringBuffer = new std::istream(Buffer);
>>
>> // Get length of buffer...
>> StringBuffer->seekg(std::streampos(0), std::ios_base::end);
>> int strLength = StringBuffer->tellg();
>> StringBuffer->seekg(std::streampos(0), std::ios_base::beg);
>>
>> // Parsing...
>> ...
>>
>> // Write out buffer (for debugging purpose)...
>> std::ofstream* pOutStream = new std::ofstream("<PATH>\\DWL.bin",
>>std::ios_base::out | std::ios_base::trunc | std::ios_base::binary);
>> pOutStream->write(Result, strLength);
>> pOutStream->close();
>>
>>Afer that its size is only 1kB!
>>And this happens with all binary files.
>>All files are just 1kB when written to disk...
>>
>>Doing the eqivalent operation for ASCII files works...
>>
>>I don't understand why this happens :-|
>>
>>Is there some magic option I must enable in order to make binary
>>downloads work? I don't think it's so, but maybe...
>>
>>Can someone test the Code and tell me his experience with it?
>>
>>Hoping to hear from you soon.
>>
>>Regards, Nazario.
>>_______________________________________________
>>cURLpp mailing list
>>cURLpp_at_rrette.com
>>http://www.rrette.com/mailman/listinfo/curlpp
>
>

-- 
Spanne den Bogen, aber schieße nicht los!
Noch gefürchtet zu sein ist wirksamer!
(altes chinesisches Sprichwort)
_______________________________________________
cURLpp mailing list
cURLpp_at_rrette.com
http://www.rrette.com/mailman/listinfo/curlpp
Received on 2005-06-17

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET