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