Browse Source

downloader: Implement VirtualFileHTTP::read_file()

rdb 4 years ago
parent
commit
84c2a18d00
2 changed files with 22 additions and 0 deletions
  1. 20 0
      panda/src/downloader/virtualFileHTTP.cxx
  2. 2 0
      panda/src/downloader/virtualFileHTTP.h

+ 20 - 0
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.

+ 2 - 0
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;