D1: std.md5: corrections for the given example

notna notna.remove.this at ist-einmalig.de
Thu Sep 17 13:07:22 PDT 2009


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);
	
}


More information about the Digitalmars-d-learn mailing list