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

Unified Diff: sdk/lib/core/resource.dart

Issue 1181663002: Add Resource class. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add suppression for analyzer warnings. Created 5 years, 6 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 | « sdk/lib/core/core_sources.gypi ('k') | tests/try/poi/serialize_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/resource.dart
diff --git a/sdk/lib/core/resource.dart b/sdk/lib/core/resource.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9bb88d117562999c377ea67da7900d48d6eac34f
--- /dev/null
+++ b/sdk/lib/core/resource.dart
@@ -0,0 +1,52 @@
+// Copyright (c) 2015, 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.
+
+part of dart.core;
+
+/**
+ * A resource that can be read into the program.
+ *
+ * A resource is data that can be located using a URI and read into
+ * the program at runtime.
+ * The URI may use the `package` scheme to read resources provided
+ * along with package sources.
+ */
+abstract class Resource {
+ /**
+ * Creates a resource object with the given [uri] as location.
+ *
+ * The `uri` is a string containing a valid URI.
+ * If the string is not a valid URI, using any of the functions on
+ * the resource object will fail.
+ *
+ * The URI may be relative, in which case it will be resolved
+ * against [Uri.base] before being used.
+ *
+ * The URI may use the `package` scheme, which is always supported.
+ * Other schemes may also be supported where possible.
+ */
+ external const factory Resource(String uri);
+
+ /**
+ * The location `uri` of this resource.
+ *
+ * This is a [Uri] of the `uri` parameter given to the constructor.
+ * If the parameter was not a valid URI, reading `uri` may fail.
+ */
+ Uri get uri;
+
+ /** Read the resource content as a stream of bytes. */
+ Stream<List<int>> openRead();
+
+ /** Read the resource content. */
+ Future<List<int>> readAsBytes();
+
+ /**
+ * Read the resource content as a string.
+ *
+ * The content is decoded into a string using an [Encoding].
+ * If no other encoding is provided, it defaults to UTF-8.
+ */
+ Future<String> readAsString({Encoding encoding});
+}
« no previous file with comments | « sdk/lib/core/core_sources.gypi ('k') | tests/try/poi/serialize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698