Add upload method

This commit is contained in:
Nikola Knezevic 2020-04-06 23:34:31 +02:00
parent a0c5931208
commit 7848372b0f
3 changed files with 10 additions and 2 deletions

View file

@ -706,6 +706,12 @@ DataTransferResult DataTransfer::download(const DataTransferRequest & request)
return enqueueDataTransfer(request).get();
}
DataTransferResult DataTransfer::upload(const DataTransferRequest & request)
{
/* Note: this method is the same as download, but helps in readability */
return enqueueDataTransfer(request).get();
}
void DataTransfer::download(DataTransferRequest && request, Sink & sink)
{
/* Note: we can't call 'sink' via request.dataCallback, because

View file

@ -82,6 +82,9 @@ struct DataTransfer
/* Synchronously download a file. */
DataTransferResult download(const DataTransferRequest & request);
/* Synchronously upload a file. */
DataTransferResult upload(const DataTransferRequest & request);
/* Download a file, writing its data to a sink. The sink will be
invoked on the thread of the caller. */
void download(DataTransferRequest && request, Sink & sink);

View file

@ -107,7 +107,7 @@ protected:
req.data = std::make_shared<string>(data); // FIXME: inefficient
req.mimeType = mimeType;
try {
getDataTransfer()->download(req);
getDataTransfer()->upload(req);
} catch (DataTransferError & e) {
throw UploadToHTTP("while uploading to HTTP binary cache at '%s': %s", cacheUri, e.msg());
}
@ -174,4 +174,3 @@ static RegisterStoreImplementation regStore([](
});
}