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

Side by Side Diff: pkg/http/lib/src/utils.dart

Issue 68103027: Serialize binary barback assets using typed arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/barback/lib/src/utils.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library utils; 5 library utils;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:typed_data'; 10 import 'dart:typed_data';
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 101
102 /// A regular expression that matches strings that are composed entirely of 102 /// A regular expression that matches strings that are composed entirely of
103 /// ASCII-compatible characters. 103 /// ASCII-compatible characters.
104 final RegExp _ASCII_ONLY = new RegExp(r"^[\x00-\x7F]+$"); 104 final RegExp _ASCII_ONLY = new RegExp(r"^[\x00-\x7F]+$");
105 105
106 /// Returns whether [string] is composed entirely of ASCII-compatible 106 /// Returns whether [string] is composed entirely of ASCII-compatible
107 /// characters. 107 /// characters.
108 bool isPlainAscii(String string) => _ASCII_ONLY.hasMatch(string); 108 bool isPlainAscii(String string) => _ASCII_ONLY.hasMatch(string);
109 109
110 /// Converts [input] into a [Uint8List]. If [input] is a [TypedData], this just 110 /// Converts [input] into a [Uint8List].
111 /// returns a view on [input]. 111 ///
112 /// If [input] is a [TypedData], this just returns a view on [input].
112 Uint8List toUint8List(List<int> input) { 113 Uint8List toUint8List(List<int> input) {
113 if (input is Uint8List) return input; 114 if (input is Uint8List) return input;
114 if (input is TypedData) { 115 if (input is TypedData) return new Uint8List.view(input.buffer);
115 // TODO(nweiz): remove this "as" check when issue 11080 is fixed. 116 return new Uint8List.fromList(input);
116 return new Uint8List.view((input as TypedData).buffer);
117 }
118 var output = new Uint8List(input.length);
119 output.setRange(0, input.length, input);
120 return output;
121 } 117 }
122 118
123 /// If [stream] is already a [ByteStream], returns it. Otherwise, wraps it in a 119 /// If [stream] is already a [ByteStream], returns it. Otherwise, wraps it in a
124 /// [ByteStream]. 120 /// [ByteStream].
125 ByteStream toByteStream(Stream<List<int>> stream) { 121 ByteStream toByteStream(Stream<List<int>> stream) {
126 if (stream is ByteStream) return stream; 122 if (stream is ByteStream) return stream;
127 return new ByteStream(stream); 123 return new ByteStream(stream);
128 } 124 }
129 125
130 /// Calls [onDone] once [stream] (a single-subscription [Stream]) is finished. 126 /// Calls [onDone] once [stream] (a single-subscription [Stream]) is finished.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 /// The return values of all [Future]s are discarded. Any errors will cause the 226 /// The return values of all [Future]s are discarded. Any errors will cause the
231 /// iteration to stop and will be piped through the return value. 227 /// iteration to stop and will be piped through the return value.
232 Future forEachFuture(Iterable input, Future fn(element)) { 228 Future forEachFuture(Iterable input, Future fn(element)) {
233 var iterator = input.iterator; 229 var iterator = input.iterator;
234 Future nextElement(_) { 230 Future nextElement(_) {
235 if (!iterator.moveNext()) return new Future.value(); 231 if (!iterator.moveNext()) return new Future.value();
236 return fn(iterator.current).then(nextElement); 232 return fn(iterator.current).then(nextElement);
237 } 233 }
238 return nextElement(null); 234 return nextElement(null);
239 } 235 }
OLDNEW
« no previous file with comments | « pkg/barback/lib/src/utils.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698