D1: std.md5: corrections for the given example

downs default_357-line at yahoo.de
Thu Sep 17 04:48:43 PDT 2009


notna wrote:
> 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;
scope file = new File(fileName, FileMode.In);
>     MD5_CTX context;
>     int len;
// int len;
>     ubyte[4 * 1024] buffer;
>     ubyte digest[16];
> 
>     file.open(fileName, FileMode.In);   
// file.open(fileName, FileMode.In);
>     context.start();
>     while ((len = file.readBlock(buffer.ptr, buffer.sizeof)) != 0)

while (auto len = file.readBlock(buffer.ptr, buffer.sizeof))

>         context.update(buffer[0 .. len]);
>     context.finish(digest);
>     file.close();
>     
// What's up with this?
>     string MD5Sum = (digestToString(digest));
>     return MD5Sum;
// return digestToString(digest);
>     
> }
> 
> Regards
> notna


More information about the Digitalmars-d-learn mailing list