Phobos function to check if files are identical?

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 13 10:55:09 PDT 2017


P.P.S.  It's not overly hard to write an alternative version of
std.stdio.chunks that returns a real range. Something like this should
do:

	// Warning: untested code
	auto realChunks(File f, size_t blockSize)
	{
		static struct Result
		{
			private File f;
			private ubyte[] buffer;
			bool empty = true;
			ubyte[] front;

			this(File _f, size_t blockSize)
			{
				f = _f;
				buffer.length = blockSize;
				empty = false;
				popFront();
			}
			void popFront()
			{
				front = f.rawRead(buffer);
				if (front.length == 0)
					empty = true;
			}
		}
		return Result(f, blockSize);
	}


T

-- 
A program should be written to model the concepts of the task it performs rather than the physical world or a process because this maximizes the potential for it to be applied to tasks that are conceptually similar and, more important, to tasks that have not yet been conceived. -- Michael B. Allen


More information about the Digitalmars-d-learn mailing list