Turi Create  4.0
curl_downloader.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_UTIL_CURL_DOWNLOADER_HPP
7 #define TURI_UTIL_CURL_DOWNLOADER_HPP
8 #include <tuple>
9 #include <string>
10 #include <cstdlib>
11 
12 namespace turi {
13 /**
14  * \ingroup fileio
15  * Downloads a given URL into a given output file
16  * \code
17  * retcode = download_url("http://google.com", "google.html");
18  * \endcode
19  * Returns 0 on success, non-zero (a curl error code) on failure.
20  */
21 int download_url(std::string url, std::string output_file);
22 
23 
24 /**
25  * \ingroup fileio
26  * Downlaods a given URL returning the local filename it has been downloaded to.
27  * If the url is a remote URL, the URL will be downloaded to a temporary local
28  * file (created using tmpnam), and the local file name returned. If the url is
29  * a local file, the local filename will be returned directly.
30  *
31  * \returns A tuple of (error_code, is_temporary, local_file_name)
32  * Error_code is non-zero on failure, in which case the other arguments
33  * should be ignored. is_temporary is true if the URL is a remote URL.
34  * local_file_name contains the local file name in which the data can be
35  * accessed.
36  *
37  * \code
38  * std::tie(status, is_temporary, filename) = download_url("http://google.com");
39  * \endcode
40  * Returns 0 on success, non-zero (a curl error code) on failure.
41  */
42 std::tuple<int, bool, std::string> download_url(std::string url);
43 
44 /**
45  * Returns the curl error string for a curl error code returned by download_url.
46  */
47 std::string get_curl_error_string(int status);
48 }
49 
50 #endif
int download_url(std::string url, std::string output_file)
std::string get_curl_error_string(int status)