summaryrefslogtreecommitdiffstats
path: root/api/logic/net/ByteArraySink.h
blob: c81b952b8f0ad1838ad31d56001b004a223b458e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include "Sink.h"

namespace Net {
/*
 * Sink object for downloads that uses an external QByteArray it doesn't own as a target.
 */
class ByteArraySink : public Sink
{
public:
	ByteArraySink(QByteArray *output)
		:m_output(output)
	{
		// nil
	};

	virtual ~ByteArraySink()
	{
		// nil
	}

public:
	Task::Status init(QNetworkRequest & request) override
	{
		m_output->clear();
		if(initAllValidators(request))
			return Task::Status::InProgress;
		return Task::Status::Failed;
	};

	Task::Status write(QByteArray & data) override
	{
		m_output->append(data);
		if(writeAllValidators(data))
			return Task::Status::InProgress;
		return Task::Status::Failed;
	}

	Task::Status abort() override
	{
		m_output->clear();
		failAllValidators();
		return Task::Status::Failed;
	}

	Task::Status finalize(QNetworkReply &reply) override
	{
		if(finalizeAllValidators(reply))
			return Task::Status::Finished;
		return Task::Status::Failed;
	}

	bool hasLocalData() override
	{
		return false;
	}

private:
	QByteArray * m_output;
};
}