| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:async'; |
| 6 import 'dart:io'; |
| 7 |
| 8 import 'package:crypto/crypto.dart'; |
| 9 |
| 10 final _usage = 'Usage: dart hash.dart <md5|sha1|sha256> <input_filename>'; |
| 11 |
| 12 Future main(List<String> args) async { |
| 13 if (args == null || args.length != 2) { |
| 14 print(_usage); |
| 15 exit(1); |
| 16 } |
| 17 |
| 18 Hash hasher; |
| 19 |
| 20 switch (args[0]) { |
| 21 case 'md5': |
| 22 hasher = md5; |
| 23 break; |
| 24 case 'sha1': |
| 25 hasher = sha1; |
| 26 break; |
| 27 case 'sha256': |
| 28 hasher = sha256; |
| 29 break; |
| 30 default: |
| 31 print(_usage); |
| 32 exit(1); |
| 33 } |
| 34 |
| 35 var filename = args[1]; |
| 36 var input = new File(filename); |
| 37 |
| 38 if (!input.existsSync()) { |
| 39 print('File "$filename" does not exist.'); |
| 40 exit(1); |
| 41 } |
| 42 |
| 43 var value = await hasher.bind(input.openRead()).first; |
| 44 |
| 45 print(value); |
| 46 } |
| OLD | NEW |