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

Side by Side Diff: sdk/lib/io/stdio.dart

Issue 2761673002: [dart:io][windows] Use WriteFile instead of _write (Closed)
Patch Set: Correctly calculate the number of bytes consumed Created 3 years, 9 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 unified diff | Download patch
« runtime/bin/file_win.cc ('K') | « sdk/lib/io/file_impl.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) 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 part of dart.io; 5 part of dart.io;
6 6
7 const int _STDIO_HANDLE_TYPE_TERMINAL = 0; 7 const int _STDIO_HANDLE_TYPE_TERMINAL = 0;
8 const int _STDIO_HANDLE_TYPE_PIPE = 1; 8 const int _STDIO_HANDLE_TYPE_PIPE = 1;
9 const int _STDIO_HANDLE_TYPE_FILE = 2; 9 const int _STDIO_HANDLE_TYPE_FILE = 2;
10 const int _STDIO_HANDLE_TYPE_SOCKET = 3; 10 const int _STDIO_HANDLE_TYPE_SOCKET = 3;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 * the output is written. 176 * the output is written.
177 * 177 *
178 * In some situations this blocking behavior is undesirable as it does not 178 * In some situations this blocking behavior is undesirable as it does not
179 * provide the same non-blocking behavior as dart:io in general exposes. 179 * provide the same non-blocking behavior as dart:io in general exposes.
180 * Use the property [nonBlocking] to get an `IOSink` which has the non-blocking 180 * Use the property [nonBlocking] to get an `IOSink` which has the non-blocking
181 * behavior. 181 * behavior.
182 * 182 *
183 * This class can also be used to check whether `stdout` or `stderr` is 183 * This class can also be used to check whether `stdout` or `stderr` is
184 * connected to a terminal and query some terminal properties. 184 * connected to a terminal and query some terminal properties.
185 */ 185 */
186 class Stdout extends _StdFileSink implements IOSink { 186 class Stdout extends _StdSink implements IOSink {
187 final int _fd; 187 final int _fd;
188 IOSink _nonBlocking; 188 IOSink _nonBlocking;
189 189
190 Stdout._(IOSink sink, this._fd) : super(sink); 190 Stdout._(IOSink sink, this._fd) : super(sink);
191 191
192 /** 192 /**
193 * Returns true if there is a terminal attached to stdout. 193 * Returns true if there is a terminal attached to stdout.
194 */ 194 */
195 bool get hasTerminal => _hasTerminal(_fd); 195 bool get hasTerminal => _hasTerminal(_fd);
196 196
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 cancelOnError: true); 293 cancelOnError: true);
294 return completer.future; 294 return completer.future;
295 } 295 }
296 296
297 Future close() { 297 Future close() {
298 _file.closeSync(); 298 _file.closeSync();
299 return new Future.value(); 299 return new Future.value();
300 } 300 }
301 } 301 }
302 302
303 class _StdSinkHelper implements IOSink { 303 class _StdSink implements IOSink {
304 final IOSink _sink; 304 final IOSink _sink;
305 final bool _isTranslatable; 305 final bool _isTranslatable;
306 306
307 _StdSinkHelper(this._sink, this._isTranslatable); 307 _StdSink(this._sink);
308 308
309 Encoding get encoding => _sink.encoding; 309 Encoding get encoding => _sink.encoding;
310 void set encoding(Encoding encoding) { 310 void set encoding(Encoding encoding) {
311 _sink.encoding = encoding; 311 _sink.encoding = encoding;
312 } 312 }
313 313 void write(object) { _sink.write(object); }
314 void set _translation(_FileTranslation t) { 314 void writeln([object = ""]) { _sink.writeln(object); }
315 if (_isTranslatable) { 315 void writeAll(objects, [sep = ""]) { _sink.writeAll(objects, sep); }
316 _IOSinkImpl sink = _sink; 316 void add(List<int> data) { _sink.add(data); }
317 _StdConsumer target = sink._target;
318 target._file.translation = t;
319 }
320 }
321
322 void write(object) {
323 _translation = _FileTranslation.text;
324 _sink.write(object);
325 }
326
327 void writeln([object = ""]) {
328 _translation = _FileTranslation.text;
329 _sink.writeln(object);
330 }
331
332 void writeAll(objects, [sep = ""]) {
333 _translation = _FileTranslation.text;
334 _sink.writeAll(objects, sep);
335 }
336
337 void add(List<int> data) {
338 _translation = _FileTranslation.binary;
339 _sink.add(data);
340 }
341
342 void addError(error, [StackTrace stackTrace]) { 317 void addError(error, [StackTrace stackTrace]) {
343 _sink.addError(error, stackTrace); 318 _sink.addError(error, stackTrace);
344 } 319 }
345 320 void writeCharCode(int charCode) { _sink.writeCharCode(charCode); }
346 void writeCharCode(int charCode) { 321 Future addStream(Stream<List<int>> stream) => _sink.addStream(stream);
347 _translation = _FileTranslation.text;
348 _sink.writeCharCode(charCode);
349 }
350
351 Future addStream(Stream<List<int>> stream) {
352 _translation = _FileTranslation.binary;
353 return _sink.addStream(stream);
354 }
355
356 Future flush() => _sink.flush(); 322 Future flush() => _sink.flush();
357 Future close() => _sink.close(); 323 Future close() => _sink.close();
358 Future get done => _sink.done; 324 Future get done => _sink.done;
359 } 325 }
360 326
361 class _StdFileSink extends _StdSinkHelper {
362 // The target of `sink` is expected to be a _StdConsumer.
363 _StdFileSink(IOSink sink) : super(sink, true);
364 }
365
366 class _StdSocketSink extends _StdSinkHelper {
367 _StdSocketSink(IOSink sink) : super(sink, false);
368 }
369
370 /// The type of object a standard IO stream is attached to. 327 /// The type of object a standard IO stream is attached to.
371 class StdioType { 328 class StdioType {
372 static const StdioType TERMINAL = const StdioType._("terminal"); 329 static const StdioType TERMINAL = const StdioType._("terminal");
373 static const StdioType PIPE = const StdioType._("pipe"); 330 static const StdioType PIPE = const StdioType._("pipe");
374 static const StdioType FILE = const StdioType._("file"); 331 static const StdioType FILE = const StdioType._("file");
375 static const StdioType OTHER = const StdioType._("other"); 332 static const StdioType OTHER = const StdioType._("other");
376 final String name; 333 final String name;
377 const StdioType._(this.name); 334 const StdioType._(this.name);
378 String toString() => "StdioType: $name"; 335 String toString() => "StdioType: $name";
379 } 336 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 } 406 }
450 407
451 class _StdIOUtils { 408 class _StdIOUtils {
452 external static _getStdioOutputStream(int fd); 409 external static _getStdioOutputStream(int fd);
453 external static Stdin _getStdioInputStream(); 410 external static Stdin _getStdioInputStream();
454 411
455 /// Returns the socket type or `null` if [socket] is not a builtin socket. 412 /// Returns the socket type or `null` if [socket] is not a builtin socket.
456 external static int _socketType(Socket socket); 413 external static int _socketType(Socket socket);
457 external static _getStdioHandleType(int fd); 414 external static _getStdioHandleType(int fd);
458 } 415 }
OLDNEW
« runtime/bin/file_win.cc ('K') | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698