Support response data streaming and add an example file downloader.
This commit is contained in:
+24
-1
@@ -147,8 +147,18 @@ private:
|
||||
// the memory.
|
||||
class FileBody : public Body {
|
||||
public:
|
||||
// For message to be sent out.
|
||||
FileBody(const Path& path, std::size_t chunk_size);
|
||||
|
||||
// For message received.
|
||||
// No |chunk_size| is needed since you don't iterate the payload of a
|
||||
// received message.
|
||||
// If |auto_delete| is true, the file will be deleted on destructor unless it
|
||||
// is moved to another path (see Move()).
|
||||
FileBody(const Path& path, bool auto_delete = false);
|
||||
|
||||
~FileBody() override;
|
||||
|
||||
std::size_t GetSize() const override {
|
||||
return size_;
|
||||
}
|
||||
@@ -159,13 +169,26 @@ public:
|
||||
|
||||
void Dump(std::ostream& os, const std::string& prefix) const override;
|
||||
|
||||
// Move (or rename) the file.
|
||||
// Used to move the streamed file of the received message to a new place.
|
||||
// Applicable to both client and server.
|
||||
// After move, the original path will be reset to empty.
|
||||
// If |new_path| and |path_| resolve to the same file, do nothing and just
|
||||
// return false.
|
||||
// If |new_path| resolves to an existing non-directory file, it is removed.
|
||||
// If |new_path| resolves to an existing directory, it is removed if empty
|
||||
// on ISO/IEC 9945 but is an error on Windows.
|
||||
// See boost::filesystem::rename() for more details.
|
||||
bool Move(const Path& new_path);
|
||||
|
||||
private:
|
||||
Path path_;
|
||||
std::size_t chunk_size_;
|
||||
bool auto_delete_;
|
||||
|
||||
std::size_t size_; // File size in bytes
|
||||
|
||||
boost::filesystem::ifstream stream_;
|
||||
boost::filesystem::ifstream ifstream_;
|
||||
std::string chunk_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user