Phobos function to check if files are identical?
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Mar 13 12:29:31 PDT 2017
On Mon, Mar 13, 2017 at 10:47:09AM -0700, H. S. Teoh via Digitalmars-d-learn wrote:
[...]
> P.S. I just realized that std.stdio.chunks() doesn't return a range.
> Bah. File an enhancement request. I might even submit a PR for it. ;-)
[...]
> P.P.S. It's not overly hard to write an alternative version of
> std.stdio.chunks that returns a real range.
[...]
Bah, I'm an idiot. Just use File.byChunk instead of .chunks. Here's a
fully-working example:
import std.stdio;
bool equal(File f1, File f2)
{
import std.algorithm.comparison : equal;
enum bufSize = 4096;
return f1.byChunk(bufSize).equal(f2.byChunk(bufSize));
}
int main(string[] args) {
if (args.length < 3)
{
stderr.writeln("Please specify filenames");
return 1;
}
if (equal(File(args[1]), File(args[2])))
writeln("Files are identical.");
else
writeln("Files differ.");
return 0;
}
T
--
INTEL = Only half of "intelligence".
More information about the Digitalmars-d-learn
mailing list