c++ - libcurl automatically replacing line feed with line feed + carriage return -


as title says when downloading , saving libcurl replacing lf lf + cr. fine text documents. binary disaster. tried

curl_easy_setopt(curl, curlopt_crlf, 0l); 

how disable thing. i'm running on windows , curl 7.40.0

#include <iostream> #include <curl/curl.h>  using namespace std;  curl *curl; curlcode res;  size_t file_write_callback(char *ptr, size_t size, size_t nmemb, void *userdata) {     fwrite(ptr,size,nmemb,(file *)userdata);     return nmemb; }  int main(void) {     file * pfile;     pfile = fopen ("myfile.png","w");      curl = curl_easy_init();     curl_easy_setopt(curl, curlopt_url, "http://www.dilushan.tk/media/128px_feed.png");     curl_easy_setopt(curl, curlopt_followlocation, 1l);      if (pfile!=null)     {         curl_easy_setopt(curl, curlopt_writedata, pfile);         curl_easy_setopt(curl, curlopt_writefunction, file_write_callback);         res = curl_easy_perform(curl);     }     fclose (pfile);     return 0; } 

libburl not culprit, underlying system library is. because windows has notion of binary files no conversion should occur, , text files end of lines represented crlf (\r\n) on disk , \n in c or c++.

and fix quite easy : use b (for binary) in mode string in open :

pfile = fopen ("myfile.png","wb"); 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -