Libcurl自动将换行替换为换行+回车
libcurl automatically replacing line feed with line feed + carriage return
正如标题所说,当下载一些东西并保存libcurl时,将所有的LF替换为LF + CR,这对于文本文档来说是好的。但对于二进制来说,这是一场灾难。我已经试过了
curl_easy_setopt(curl, CURLOPT_CRLF, 0L);
如何禁用这个东西。我在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不是罪魁祸首,而是底层系统库。因为Windows有一个二进制文件的概念,它不应该发生转换,而文本文件的行尾在磁盘上表示为CrLf (rn
),而在C或c++中仅表示为n
。
和修复是很容易的:只需使用b
(二进制)模式字符串在open
:
pFile = fopen ("myfile.png","wb");
相关文章:
- 使用一个考虑到std::map中键值的滚动或换行的键
- 如何防止clang格式在流运算符调用之间添加换行符<<
- C/C++ - 查询平台相关的换行符(用于内存映射文件)
- 在 Stream C++ 文本之前有一个额外的换行符
- 流:CSV 文件中的换行符
- 将缓冲区复制到剪贴板 [换行错误]
- 如何在三元条件运算符中添加换行符和连接? :在 C++ 中
- Clang-格式:在多行语句之后的换行符上打开大括号
- 如何正确转发/换行static_cast?
- 在输出流中插入换行符
- 防止控制台在通道字符(在 c++ 中)中输入空格(即空格、制表符和换行符)
- Linux 终端:回车卡在换行处
- 程序找不到回车符或换行符。退货超出范围
- 使用 c++ 查找回车/换行组合
- 使用boost::regex时,如何指定回车符和换行符匹配
- C/C++如何在回车后从stdin中读取,连续命中两次或在两个换行后
- C++ 字符串中的回车符和换行符
- Libcurl自动将换行替换为换行+回车
- 在WxWidgets文本控件中按回车时防止换行
- CStdioFile::WriteString为换行添加额外的回车符