OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library pub.validator.size; | |
6 | |
7 import 'dart:async'; | 5 import 'dart:async'; |
8 import 'dart:math' as math; | 6 import 'dart:math' as math; |
9 | 7 |
10 import '../entrypoint.dart'; | 8 import '../entrypoint.dart'; |
11 import '../validator.dart'; | 9 import '../validator.dart'; |
12 | 10 |
13 /// The maximum size of the package to upload (100 MB). | 11 /// The maximum size of the package to upload (100 MB). |
14 const _MAX_SIZE = 100 * 1024 * 1024; | 12 const _MAX_SIZE = 100 * 1024 * 1024; |
15 | 13 |
16 /// A validator that validates that a package isn't too big. | 14 /// A validator that validates that a package isn't too big. |
17 class SizeValidator extends Validator { | 15 class SizeValidator extends Validator { |
18 final Future<int> packageSize; | 16 final Future<int> packageSize; |
19 | 17 |
20 SizeValidator(Entrypoint entrypoint, this.packageSize) | 18 SizeValidator(Entrypoint entrypoint, this.packageSize) |
21 : super(entrypoint); | 19 : super(entrypoint); |
22 | 20 |
23 Future validate() { | 21 Future validate() { |
24 return packageSize.then((size) { | 22 return packageSize.then((size) { |
25 if (size <= _MAX_SIZE) return; | 23 if (size <= _MAX_SIZE) return; |
26 var sizeInMb = (size / math.pow(2, 20)).toStringAsPrecision(4); | 24 var sizeInMb = (size / math.pow(2, 20)).toStringAsPrecision(4); |
27 errors.add("Your package is $sizeInMb MB. Hosted packages must be " | 25 errors.add("Your package is $sizeInMb MB. Hosted packages must be " |
28 "smaller than 100 MB."); | 26 "smaller than 100 MB."); |
29 }); | 27 }); |
30 } | 28 } |
31 } | 29 } |
32 | 30 |
OLD | NEW |