Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Unified Diff: utils/pub/validator/size.dart

Issue 12094093: Add a validator that tests the size of pub packages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/validator.dart ('k') | utils/tests/pub/validator_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/validator/size.dart
diff --git a/utils/pub/validator/size.dart b/utils/pub/validator/size.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ebe513030ede49862b852cc8c58467dcbf01d326
--- /dev/null
+++ b/utils/pub/validator/size.dart
@@ -0,0 +1,32 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// 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.
+
+library size_validator;
+
+import 'dart:async';
+import 'dart:math' as math;
+
+import '../entrypoint.dart';
+import '../validator.dart';
+
+/// The maximum size of the package to upload (10 MB).
+final _MAX_SIZE = 10 * math.pow(2, 20);
Bob Nystrom 2013/02/01 01:29:44 This should either be _maxSize (since it's not con
nweiz 2013/02/01 02:08:00 Done.
+
+/// A validator that validates that a package isn't too big.
+class SizeValidator extends Validator {
+ final Future<int> packageSize;
+
+ SizeValidator(Entrypoint entrypoint, this.packageSize)
+ : super(entrypoint);
+
+ Future validate() {
+ return packageSize.then((size) {
+ if (size <= _MAX_SIZE) return;
+ var sizeInMb = (size / math.pow(2, 20)).toStringAsPrecision(4);
+ errors.add("Your package is $sizeInMb MB. Hosted packages may be at most "
+ "10 MB large.");
Bob Nystrom 2013/02/01 01:29:44 How about "Hosted packages must be smaller than 10
nweiz 2013/02/01 02:08:00 Done.
+ });
+ }
+}
+
« no previous file with comments | « utils/pub/validator.dart ('k') | utils/tests/pub/validator_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698