From 84c2a18d003c183507afea7f042ca9f90240734b Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 15 Feb 2021 11:18:13 +0100 Subject: [PATCH] downloader: Implement VirtualFileHTTP::read_file() --- panda/src/downloader/virtualFileHTTP.cxx | 20 ++++++++++++++++++++ panda/src/downloader/virtualFileHTTP.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/panda/src/downloader/virtualFileHTTP.cxx b/panda/src/downloader/virtualFileHTTP.cxx index 527e9c619b..dcb9036d87 100644 --- a/panda/src/downloader/virtualFileHTTP.cxx +++ b/panda/src/downloader/virtualFileHTTP.cxx @@ -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. diff --git a/panda/src/downloader/virtualFileHTTP.h b/panda/src/downloader/virtualFileHTTP.h index eaf63f0465..219390f4aa 100644 --- a/panda/src/downloader/virtualFileHTTP.h +++ b/panda/src/downloader/virtualFileHTTP.h @@ -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;