Re: Phobos function to check if files are identical?

2017-03-14 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 14 March 2017 at 18:26:52 UTC, flamencofantasy wrote: import std.mmfile; auto f1 = new MmFile("file1"); auto f2 = new MmFile("file2"); return f1[] == f2[]; Nice! I don't have experience with memory-mapped files. What are the pros and cons?

Re: Phobos function to check if files are identical?

2017-03-14 Thread flamencofantasy via Digitalmars-d-learn
On Tuesday, 14 March 2017 at 08:31:20 UTC, XavierAP wrote: On Tuesday, 14 March 2017 at 08:12:16 UTC, Andrea Fontana wrote: First I would check if the files have different size or if they are the same file (same path, symlink, etc). Good idea. Good reason to have it in std.file. There might

Re: Phobos function to check if files are identical?

2017-03-14 Thread XavierAP via Digitalmars-d-learn
On Tuesday, 14 March 2017 at 08:12:16 UTC, Andrea Fontana wrote: First I would check if the files have different size or if they are the same file (same path, symlink, etc). Good idea. Good reason to have it in std.file. There might also be platform dependent shortcuts?

Re: Phobos function to check if files are identical?

2017-03-14 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 13 March 2017 at 17:47:09 UTC, H. S. Teoh wrote: bool isEqual(string filename1, string filename2) { import std.algorithm.comparison : equal; import std.range : zip; import std.stdio : File, chunks; auto f1 = File(

Re: Phobos function to check if files are identical?

2017-03-13 Thread XavierAP via Digitalmars-d-learn
On Monday, 13 March 2017 at 17:47:09 UTC, H. S. Teoh wrote: Binary comparison is easy. Just read the files by fixed-sized chunks and compare them. Follow up question... What is the best @safe way? Since File.byChunk() is @system. Just out of curiosity, I would rather use it and flag my code

Re: Phobos function to check if files are identical?

2017-03-13 Thread XavierAP via Digitalmars-d-learn
On Monday, 13 March 2017 at 17:47:09 UTC, H. S. Teoh wrote: Why it is not easy to do by hand? Sorry typo, I had intended to type "I know it is easy"

Re: Phobos function to check if files are identical?

2017-03-13 Thread H. S. Teoh via Digitalmars-d-learn
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 ver

Re: Phobos function to check if files are identical?

2017-03-13 Thread H. S. Teoh via Digitalmars-d-learn
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 {

Re: Phobos function to check if files are identical?

2017-03-13 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 13, 2017 at 04:50:49PM +, XavierAP via Digitalmars-d-learn wrote: > It's not easy to do by hand of course, but I was wondering if there > was one simple function taking two file names and just returning a > bool or something like that. I haven't found it in std.file. Why it is not

Phobos function to check if files are identical?

2017-03-13 Thread XavierAP via Digitalmars-d-learn
It's not easy to do by hand of course, but I was wondering if there was one simple function taking two file names and just returning a bool or something like that. I haven't found it in std.file. If such a function doesn't exist in Phobos but there's a good implementation in some other librar