Stewart Gordon schrieb:
downs wrote:
<snip>
while (auto len = file.readBlock(buffer.ptr, buffer.sizeof))
<snip>
md5_example_2.d(7): expression expected, not 'auto'
md5_example_2.d(7): found 'len' when expecting ')'
md5_example_2.d(7): found '=' instead of statement
(this is line 7 after I removed comments and blank lines from your edit)
Stewart.
yeah, you're right again.
sorr, I had'n the time to test as I posted the message before. that's
why I wrote "it looks cleaner" :-(
anyhow, also the " != 0 " is needed. otherwise I get this:
Error: '=' does not give a boolean result
so, the working code is:
string MD5File(string fileName) {
File file = new File(fileName, FileMode.In);
MD5_CTX context;
int len;
ubyte[4 * 1024] buffer;
ubyte digest[16];
context.start();
while ((len = file.readBlock(buffer.ptr, buffer.sizeof)) != 0)
context.update(buffer[0 .. len]);
context.finish(digest);
file.close();
return digestToString(digest);
}