1/*
2 * Copyright 2018, Andrew Lindesay <apl@lindesay.co.nz>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5#include "DataIOUtils.h"
6
7
8#define BUFFER_SIZE 1024
9
10
11status_t
12DataIOUtils::Copy(BDataIO* target, BDataIO* source, size_t size)
13{
14	status_t result = B_OK;
15	uint8 buffer[BUFFER_SIZE];
16
17	while (size > 0 && result == B_OK) {
18		size_t sizeToRead = size;
19		size_t sizeRead = 0;
20
21		if (sizeToRead > BUFFER_SIZE)
22			sizeToRead = BUFFER_SIZE;
23
24		result = source->ReadExactly(buffer, sizeToRead, &sizeRead);
25
26		if (result == B_OK)
27			result = target->WriteExactly(buffer, sizeRead);
28
29		size -= sizeRead;
30	}
31
32	return result;
33}