| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Generic utility functions. Stuff that should possibly be in core. | 5 /// Generic utility functions. Stuff that should possibly be in core. |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import "dart:convert"; | 7 import "dart:convert"; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:math' as math; | 9 import 'dart:math' as math; |
| 10 | 10 |
| 11 import "package:convert/convert.dart"; | |
| 12 import "package:crypto/crypto.dart" as crypto; | 11 import "package:crypto/crypto.dart" as crypto; |
| 13 import 'package:path/path.dart' as path; | 12 import 'package:path/path.dart' as path; |
| 14 import "package:stack_trace/stack_trace.dart"; | 13 import "package:stack_trace/stack_trace.dart"; |
| 15 | 14 |
| 16 import 'exceptions.dart'; | 15 import 'exceptions.dart'; |
| 17 import 'io.dart'; | 16 import 'io.dart'; |
| 18 import 'log.dart' as log; | 17 import 'log.dart' as log; |
| 19 | 18 |
| 20 export 'asset/dart/utils.dart'; | 19 export 'asset/dart/utils.dart'; |
| 21 | 20 |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 /// Returns whether or not [str] ends with [matcher]. | 480 /// Returns whether or not [str] ends with [matcher]. |
| 482 bool endsWithPattern(String str, Pattern matcher) { | 481 bool endsWithPattern(String str, Pattern matcher) { |
| 483 for (var match in matcher.allMatches(str)) { | 482 for (var match in matcher.allMatches(str)) { |
| 484 if (match.end == str.length) return true; | 483 if (match.end == str.length) return true; |
| 485 } | 484 } |
| 486 return false; | 485 return false; |
| 487 } | 486 } |
| 488 | 487 |
| 489 /// Returns the hex-encoded sha1 hash of [source]. | 488 /// Returns the hex-encoded sha1 hash of [source]. |
| 490 String sha1(String source) => | 489 String sha1(String source) => |
| 491 hex.encode(crypto.sha1.convert(source.codeUnits).bytes); | 490 crypto.sha1.convert(UTF8.encode(source)).toString(); |
| 492 | 491 |
| 493 /// Returns the base64-encoded sha1 hash of [stream]. | 492 /// Returns the base64-encoded sha1 hash of [stream]. |
| 494 Future<String> sha1Stream(Stream<List<int>> stream) async { | 493 Future<String> sha1Stream(Stream<List<int>> stream) async { |
| 495 crypto.Digest digest; | 494 crypto.Digest digest; |
| 496 | 495 |
| 497 var digestSink = new ChunkedConversionSink<crypto.Digest>.withCallback( | 496 var digestSink = new ChunkedConversionSink<crypto.Digest>.withCallback( |
| 498 (digests) { | 497 (digests) { |
| 499 digest = digests.single; | 498 digest = digests.single; |
| 500 }); | 499 }); |
| 501 | 500 |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 } else { | 971 } else { |
| 973 throw new ApplicationException(message); | 972 throw new ApplicationException(message); |
| 974 } | 973 } |
| 975 } | 974 } |
| 976 | 975 |
| 977 /// Throw a [DataException] with [message] to indicate that the command has | 976 /// Throw a [DataException] with [message] to indicate that the command has |
| 978 /// failed because of invalid input data. | 977 /// failed because of invalid input data. |
| 979 /// | 978 /// |
| 980 /// This will report the error and cause pub to exit with [exit_codes.DATA]. | 979 /// This will report the error and cause pub to exit with [exit_codes.DATA]. |
| 981 void dataError(String message) => throw new DataException(message); | 980 void dataError(String message) => throw new DataException(message); |
| OLD | NEW |