Mercurial > codedump
comparison decodeurl.cpp @ 8:b3d9104ad918
Rename decode.cpp to decodeurl.cpp
committer: GitHub <noreply@github.com>
| author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
|---|---|
| date | Sat, 23 Jan 2021 05:20:25 -0500 |
| parents | decode.cpp@aac9a23bd027 |
| children |
comparison
equal
deleted
inserted
replaced
| 7:0ea9cae1339b | 8:b3d9104ad918 |
|---|---|
| 1 // requires libcurl | |
| 2 #include <curl/curl.h> | |
| 3 #include <iostream> | |
| 4 #include <string.h> | |
| 5 #include <fstream> | |
| 6 | |
| 7 int main(int argc, char * argv[]) { | |
| 8 if (argc != 3) { | |
| 9 std::cout << "usage: " << argv[0] << " <input> <output>"; | |
| 10 return 0; | |
| 11 } | |
| 12 std::string encoded; | |
| 13 CURL * curl = curl_easy_init(); | |
| 14 char somedata[256]; | |
| 15 std::ifstream in (argv[1], std::ios:: in | std::ios::binary); | |
| 16 if (in) { | |
| 17 in .seekg(0, std::ios::end); | |
| 18 encoded.resize( in .tellg()); in .seekg(0, std::ios::beg); in .read( & encoded[0], encoded.size()); in .close(); | |
| 19 } | |
| 20 int outlength; | |
| 21 char * cres = curl_easy_unescape(curl, encoded.c_str(), encoded.length(), & outlength); | |
| 22 std::string res(cres, cres + outlength); | |
| 23 curl_free(cres); | |
| 24 curl_easy_cleanup(curl); | |
| 25 std::ofstream myfile2; | |
| 26 myfile2.open(argv[2]); | |
| 27 myfile2 << res; | |
| 28 myfile2.close(); | |
| 29 return 0; | |
| 30 } |
