downloader: Implement VirtualFileHTTP::read_file()

This commit is contained in:
rdb 2021-02-15 11:18:13 +01:00
parent 20bdd32765
commit 84c2a18d00
2 changed files with 22 additions and 0 deletions

View File

@ -140,6 +140,26 @@ open_read_file(bool auto_unwrap) const {
return return_file(strstream, auto_unwrap);
}
/**
* Fills up the indicated pvector with the contents of the file, if it is a
* regular file. Returns true on success, false otherwise.
*/
bool VirtualFileHTTP::
read_file(vector_uchar &result, bool auto_unwrap) const {
if (_status_only) {
return false;
}
Ramfile ramfile;
if (!_channel->download_to_ram(&ramfile, false)) {
return false;
}
const string &data = ramfile.get_data();
std::copy(data.begin(), data.end(), std::back_inserter(result));
return true;
}
/**
* Downloads the entire file from the web server into the indicated iostream.
* Returns true on success, false on failure.

View File

@ -51,6 +51,8 @@ public:
virtual std::streamsize get_file_size() const;
virtual time_t get_timestamp() const;
virtual bool read_file(vector_uchar &result, bool auto_unwrap) const;
private:
bool fetch_file(std::ostream *buffer_stream) const;
std::istream *return_file(std::istream *buffer_stream, bool auto_unwrap) const;