D1: std.md5: corrections for the given example

notna notna.remove.this at ist-einmalig.de
Wed Sep 16 17:25:55 PDT 2009


Stewart Gordon schrieb:
> The .ptr is necessary, but the cast(uint) isn't.  Even if a change of 
> type were necessary, just 1U would do.  (U is a suffix meaning unsigned. 
>  There's also L meaning long.)
> 
> Stewart.

Thank Stewart.

As the std.md5-example is not working with "unicode" file names 
(fopen...) I rewrote the "MDFile" function and use "file.readBlock" 
instead now. Maybe the std.md5 example should be changed to use a 
"file.read" or "file.readBlock".

Here is my code (I've checkedthe file exists and is readable before):

string MD5File(string fileName) {
	
	File file = new File;
	MD5_CTX context;
	int len;
	ubyte[4 * 1024] buffer;
	ubyte digest[16];

	file.open(fileName, FileMode.In);	
	context.start();
	while ((len = file.readBlock(buffer.ptr, buffer.sizeof)) != 0)
		context.update(buffer[0 .. len]);
	context.finish(digest);
	file.close();
	
	string MD5Sum = (digestToString(digest));
	return MD5Sum;
	
}

Regards
notna


More information about the Digitalmars-d-learn mailing list