MCPcopy Create free account
hub / github.com/SmingHub/Sming / copyFrom

Method copyFrom

Sming/Core/Data/Stream/ReadWriteStream.cpp:15–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13static constexpr size_t maxBufferSize = 512;
14
15size_t ReadWriteStream::copyFrom(IDataSourceStream* source, size_t size)
16{
17 if(source == nullptr || size == 0) {
18 return 0;
19 }
20
21 auto bufSize = std::min(size, maxBufferSize);
22 char buffer[bufSize];
23 size_t total = 0;
24 while(!source->isFinished()) {
25 size_t count = source->readMemoryBlock(buffer, bufSize);
26 if(count == 0) {
27 continue;
28 }
29 auto written = write(reinterpret_cast<uint8_t*>(buffer), count);
30 source->seek(written);
31 total += written;
32 if(written != count) {
33 break;
34 }
35 }
36
37 return total;
38}

Callers

nothing calls this directly

Calls 4

minFunction · 0.85
isFinishedMethod · 0.45
readMemoryBlockMethod · 0.45
seekMethod · 0.45

Tested by

no test coverage detected