Chromium Code Reviews| Index: example/hash.dart |
| diff --git a/example/hash.dart b/example/hash.dart |
| index 0f7900736820cd2ac3aa986c48634a7bb9824a67..891ef666ccb1d4e3010fd07247f05d055b15a7b5 100644 |
| --- a/example/hash.dart |
| +++ b/example/hash.dart |
| @@ -2,31 +2,33 @@ |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| -import 'dart:io' show exit, File; |
| -import 'package:crypto/crypto.dart' show MD5, SHA1, SHA256, CryptoUtils; |
| +import 'dart:async'; |
| +import 'dart:io'; |
| -const USAGE = 'Usage: dart hash.dart <md5|sha1|sha256> <input_filename>'; |
| +import 'package:crypto/crypto.dart'; |
| -main(List<String> args) async { |
| +const _usage = 'Usage: dart hash.dart <md5|sha1|sha256> <input_filename>'; |
|
nweiz
2016/03/23 22:28:35
This should be final, not const.
kevmoo
2016/03/23 22:49:05
Done.
|
| + |
| +Future main(List<String> args) async { |
| if (args == null || args.length != 2) { |
| - print(USAGE); |
| + print(_usage); |
| exit(1); |
| } |
| - var hasher; |
| + Hash hasher; |
| switch (args[0]) { |
| case 'md5': |
| - hasher = new MD5(); |
| + hasher = md5; |
| break; |
| case 'sha1': |
| - hasher = new SHA1(); |
| + hasher = sha1; |
| break; |
| case 'sha256': |
| - hasher = new SHA256(); |
| + hasher = sha256; |
| break; |
| default: |
| - print(USAGE); |
| + print(_usage); |
| exit(1); |
| } |
| @@ -38,11 +40,7 @@ main(List<String> args) async { |
| exit(1); |
| } |
| - await for (var bytes in input.openRead()) { |
| - hasher.add(bytes); |
| - } |
| - |
| - var hex = CryptoUtils.bytesToHex(hasher.close()); |
| + var value = await hasher.bind(input.openRead()).first; |
| - print(hex); |
| + print(value); |
| } |