http://qs1969.pair.com?node_id=1113149


in reply to MD5 checksums for Windows

Thanks for sharing!

Just an observation, which may not be relevant, since your script's output format doesn't exactly match that of md5sum (you include the file's size):

md5sum offers a -b switch, which mainly adds the "b" to the fopen call, which "has no effect; the 'b' is ignored on all POSIX conforming systems, including Linux." It also adds an asterisk to the output line to indicate that the binary mode was used, like so:

$ md5sum -b * fb8d98be1265dd88bac522e1b2182140 *foo.txt f83a0aa1f9ca0f7dd5994445ba7d9e80 *bar.txt d6a6bc0db10694a2d90e3a69648f3a03 *quz.txt

But in my experience people usually ignore the -b switch because it has no effect on those systems. On Windows, of course it's a different story, since there, fopen cares about the "b" mode (among other things, "translations involving carriage-return and linefeed characters are suppressed").

Now whether or not this is an issue at all depends on whether there's a Windows MD5 checksumming tool that defaulted to reading files in text mode. But since you're on Windows and you use binmode, if you felt like making your output more similar to that of md5sum, you could consider adding the asterisk to your output.

Replies are listed 'Best First'.
Re^2: MD5 checksums for Windows
by golux (Chaplain) on Jan 14, 2015 at 15:49 UTC
    Thanks for the suggestion!

    I was unaware of the -b switch, and you're right that the output format doesn't match that of md5sum. Since it's a pretty easy fix (less than 10 lines), I'll add a "-c" (compatibility) switch to the program now.

    say  substr+lc crypt(qw $i3 SI$),4,5
      you rock! that's been on my todo list for ages