Home » U++ Library support » U++ Core » Upp::CopyStream reports wrong size.
Re: Upp::CopyStream reports wrong size. [message #50217 is a reply to message #50214] |
Mon, 27 August 2018 20:36 |
Oblivion
Messages: 1094 Registered: August 2007
|
Senior Contributor |
|
|
By the way, why not just use GetPos()? Doesn't it work for all streams? If it works the error checking I suggested (previously) can be added.
E.g.
int64 CopyStream(Stream& dest, Stream& src, int64 count, Gate<int64, int64> progress, int chunk_size)
{
int block = (int)min<int64>(count, chunk_size);
Buffer<byte> temp(block);
int loaded;
int64 done = 0;
int64 total = count;
while(count > 0 && (loaded = src.Get(~temp, (int)min<int64>(count, block))) > 0) {
dest.Put(~temp, loaded);
int64 pos = dest.GetPos();
if(pos > done) { // at least one byte is written to dest.
count -= pos;
done = pos;
if(progress(done, total))
return -1;
}
if(dest.IsError())
break;
}
return done;
}
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Mon, 27 August 2018 21:31] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Tue May 14 13:17:06 CEST 2024
Total time taken to generate the page: 0.01224 seconds
|