OpenCPN Partial API docs
Loading...
Searching...
No Matches
downloader.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2019 Alec Leamas *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifndef DOWNLOADER_H__
25#define DOWNLOADER_H__
26
27#include <string>
28#include <ostream>
29
36public:
37 explicit Downloader(std::string url);
38
42 virtual ~Downloader() = default;
43
45 bool download(std::ostream* stream);
46
51 bool download(std::string& path);
52
54 int last_errorcode();
55
57 std::string last_error();
58
60 virtual void on_chunk(const char* buff, unsigned bytes);
61
62protected:
64 long get_filesize();
65
66 std::string url;
67 std::ostream* stream;
68 std::string error_msg;
69 int errorcode;
70};
71
72#endif // DOWNLOADER_H__
Default downloader, usable in a CLI context.
Definition downloader.h:35
bool download(std::ostream *stream)
Download url into stream, return false on errors.
virtual ~Downloader()=default
Destroy the Downloader object.
long get_filesize()
Try to get remote filesize, return 0 on failure.
std::string last_error()
Last Curl error message.
virtual void on_chunk(const char *buff, unsigned bytes)
Called when given bytes has been transferred from remote.
int last_errorcode()
Last error code, a CURLE return code.