PrismLauncher/launcher/net/ByteArraySink.h

55 lines
1.3 KiB
C
Raw Normal View History

#pragma once
#include "Sink.h"
namespace Net {
/*
* Sink object for downloads that uses an external QByteArray it doesn't own as a target.
* FIXME: It is possible that the QByteArray is freed while we're doing some operation on it,
* causing a segmentation fault.
*/
class ByteArraySink : public Sink {
public:
ByteArraySink(QByteArray* output) : m_output(output){};
virtual ~ByteArraySink() = default;
public:
auto init(QNetworkRequest& request) -> Task::State override
2018-07-15 13:51:05 +01:00
{
m_output->clear();
if (initAllValidators(request))
return Task::State::Running;
return Task::State::Failed;
2018-07-15 13:51:05 +01:00
};
auto write(QByteArray& data) -> Task::State override
2018-07-15 13:51:05 +01:00
{
m_output->append(data);
if (writeAllValidators(data))
return Task::State::Running;
return Task::State::Failed;
2018-07-15 13:51:05 +01:00
}
auto abort() -> Task::State override
2018-07-15 13:51:05 +01:00
{
m_output->clear();
failAllValidators();
return Task::State::Failed;
2018-07-15 13:51:05 +01:00
}
auto finalize(QNetworkReply& reply) -> Task::State override
2018-07-15 13:51:05 +01:00
{
if (finalizeAllValidators(reply))
return Task::State::Succeeded;
return Task::State::Failed;
2018-07-15 13:51:05 +01:00
}
auto hasLocalData() -> bool override { return false; }
private:
QByteArray* m_output;
};
} // namespace Net