Phobos provides a package called std.digest
that offers checksum and message digest algorithms through a unified API. Here, we'll create a small MD5 utility that calculates and prints the resulting digest of a file.
Let's print an MD5 digest by executing the following steps:
The code is as follows:
void main(string[] args) { import std.digest.md; import std.stdio; import std.range; File file; if(args.length > 1) file = File(args[1], "rb"); else file = stdin; MD5 digest; digest.start(); put(digest, file.byChunk(1024)); writeln(toHexString(digest.finish())); }