Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous message
Oblivion is currently offline  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;
}




[Updated on: Mon, 27 August 2018 21:31]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Folder for configuration file
Next Topic: DEPRECATED flag
Goto Forum:
  


Current Time: Tue May 14 13:17:06 CEST 2024

Total time taken to generate the page: 0.01224 seconds