diff --git a/src/client/Response.cxx b/src/client/Response.cxx index 7577d6956..9d85a27e6 100644 --- a/src/client/Response.cxx +++ b/src/client/Response.cxx @@ -56,6 +56,14 @@ Response::Format(const char *fmt, ...) noexcept return success; } +bool +Response::WriteBinary(ConstBuffer payload) noexcept +{ + return Format("binary: %zu\n", payload.size) && + Write(payload.data, payload.size) && + Write("\n"); +} + void Response::Error(enum ack code, const char *msg) noexcept { diff --git a/src/client/Response.hxx b/src/client/Response.hxx index ec8fe1044..cac365552 100644 --- a/src/client/Response.hxx +++ b/src/client/Response.hxx @@ -26,6 +26,7 @@ #include #include +template struct ConstBuffer; class Client; class TagMask; @@ -76,6 +77,14 @@ public: bool FormatV(const char *fmt, va_list args) noexcept; bool Format(const char *fmt, ...) noexcept; + /** + * Write a binary chunk; this writes the "binary" line, the + * given chunk and the trailing newline. + * + * @return true on success + */ + bool WriteBinary(ConstBuffer payload) noexcept; + void Error(enum ack code, const char *msg) noexcept; void FormatError(enum ack code, const char *fmt, ...) noexcept; }; diff --git a/src/command/FileCommands.cxx b/src/command/FileCommands.cxx index 97b5d89fe..5de92a721 100644 --- a/src/command/FileCommands.cxx +++ b/src/command/FileCommands.cxx @@ -296,14 +296,8 @@ read_stream_art(Response &r, const char *uri, size_t offset) read_size = is->Read(lock, &buffer, CHUNK_SIZE); } - r.Format("size: %" PRIoffset "\n" - "binary: %u\n", - art_file_size, - read_size - ); - - r.Write(buffer, read_size); - r.Write("\n"); + r.Format("size: %" PRIoffset "\n", art_file_size); + r.WriteBinary({buffer, read_size}); return CommandResult::OK; }