Advertisement
Guest User

dlang toHexString

a guest
Jul 19th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.62 KB | None | 0 0
  1. import std.digest.crc, std.digest.digest, std.stdio;
  2.  
  3. string computeCrc32_A(string path)
  4. {
  5.     CRC32 crc;
  6.     auto file = File(path, "rb");
  7.     foreach (ubyte[] data; chunks(file, 4096)) {
  8.         crc.put(data);
  9.     }
  10.    
  11.     return crcHexString(crc.finish());
  12. }
  13.  
  14. string computeCrc32_B(string path)
  15. {
  16.     CRC32 crc;
  17.     auto file = File(path, "rb");
  18.     foreach (ubyte[] data; chunks(file, 4096)) {
  19.         crc.put(data);
  20.     }
  21.    
  22.     return toHexString!(Order.decreasing)(crc.finish()); // return nothing or garbage
  23. }
  24.  
  25. void main()
  26. {
  27.     writeln(computeCrc32_A("file.txt"));  // OK
  28.     writeln(computeCrc32_B("file.txt"));   // write nothing or garbage
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement