OLD | NEW |
---|---|
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 /** | 5 /** |
6 * File, socket, HTTP, and other I/O support for server applications. | 6 * File, socket, HTTP, and other I/O support for server applications. |
7 * | 7 * |
8 * The IO library is used for Dart server applications, | 8 * The I/O library is used for Dart server applications, |
9 * which run on a stand-alone Dart VM from the command line. | 9 * which run on a stand-alone Dart VM from the command line. |
10 * *This library does not work in browser based applications.* | 10 * *This library does not work in browser-based applications.* |
11 * | 11 * |
12 * This library allows you to work with files, directories, | 12 * This library allows you to work with files, directories, |
13 * sockets, processes, HTTP servers and clients, and more. | 13 * sockets, processes, HTTP servers and clients, and more. |
14 * | |
15 * To use this library in your code: | |
16 * | |
17 * import 'dart:io'; | |
18 * | |
19 * Many operations related to input and output are asynchronous | |
20 * and are handled using Futures or Streams. | |
21 * Consider it a pre-requisite to learn about Futures and Streams | |
Kathy Walrath
2013/12/16 21:18:48
pre-requisite -> prerequisite
"Consider it ..." s
mem
2013/12/16 22:18:55
Done.
| |
22 * before learning about I/O. | |
23 * The [Future] and [Stream] classes are in the [dart:async] library. | |
24 * | |
25 * import 'dart:async'; | |
26 * | |
27 * ## FileSystemEntity | |
28 * | |
29 * Given a pathname, you can create a [FileSystemEntity] to represent | |
30 * whatever is at that pathname. | |
31 * Then you can query the FileSystemEntity object to get information | |
32 * using methods such as 'isDirectory', 'isFile', and 'exists'. | |
33 * Because these methods | |
Kathy Walrath
2013/12/16 21:18:48
Maybe:
Because file system access can be slow, th
mem
2013/12/16 22:18:55
Done.
mem
2013/12/16 22:18:55
Done.
| |
34 * must access the file system to determine the answer, | |
35 * the operations are performed asynchronously with a Future. | |
36 * | |
37 * FileSystemEntity.isDirectory(myPath).then((isDir) { | |
38 * if (isDir) { | |
39 * print('$myPath is a directory'); | |
40 * } else { | |
41 * print('$myPath is not a directory'); | |
42 * } | |
43 * }); | |
44 * | |
45 * ## File and Directory | |
46 * | |
47 * A [File] object represents a file in the native file system. | |
48 * A [Directory] object represents a directory in the native file system. | |
Kathy Walrath
2013/12/16 21:18:48
This is choppy. Maybe:
Each instance of [File] or
mem
2013/12/16 22:18:55
Done.
| |
49 * Both are subclasses of FileSystemEntity. | |
50 * You can manipulate the file sytem through objects of these types. | |
Kathy Walrath
2013/12/16 21:18:48
sytem!
mem
2013/12/16 22:18:55
Done.
| |
51 * For example, you can rename a file or directory: | |
52 * | |
53 * File myFile = new File('myFile.txt'); | |
54 * myFile.rename('yourFile.txt').then((_) { print('file renamed'); }); | |
55 * | |
56 * Many methods provided by the File and Directory classes | |
57 * run asynchronously and return a Future. | |
58 * | |
59 * ## HttpServer | |
60 * | |
61 * To create an Http server, we recommend that you try using | |
62 * the [http_server](https://pub.dartlang.org/packages/http_server) | |
63 * pub package, which contains | |
64 * a set of high-level classes that, together with the [HttpServer] class | |
65 * in this library, makes it easy to provide content through HTTP servers. | |
66 * | |
67 * ## Standard output, error, and input streams | |
68 * | |
69 * This library provides the standard output, error, and input | |
70 * streams, named 'stdout', 'stderr', and 'stdin', respectively. | |
71 * | |
72 * The stdout and stderr streams are both [IOSink]s and have the same set | |
73 * of methods and properties. | |
74 * | |
75 * To write a string to 'stdout': | |
76 * | |
77 * stdout.writeln('Hello, World!'); | |
78 * | |
79 * To write a list of objects to 'stderr': | |
80 * | |
81 * stderr.writeAll([ 'That ', 'is ', 'an ', 'error.', '\n']); | |
82 * | |
83 * The standard input stream is a true [Stream], so it inherits | |
84 * properties and methods from the Stream class. | |
85 * | |
86 * To read text synchronously from the command-line | |
Kathy Walrath
2013/12/16 21:18:48
command-line -> command line
(since it's not an ad
mem
2013/12/16 22:18:55
Done.
mem
2013/12/16 22:18:55
Done.
| |
87 * (the program blocks waiting for user to type information): | |
88 * | |
89 * String inputText = stdin.readLineSync(); | |
90 * | |
91 * ## Other Resources | |
Kathy Walrath
2013/12/16 21:18:48
Resources -> resources
mem
2013/12/16 22:18:55
Done.
| |
92 * | |
93 * For an introduction to I/O in Dart, see the | |
94 * [dart:io section of the library tour] | |
95 * (https://www.dartlang.org/docs/dart-up-and-running/contents/ch03.html#ch03-da rtio---file-and-socket-io-for-command-line-apps). | |
96 * | |
97 * To learn more about I/O in Dart, refer to the | |
98 * [tutorial about writing command-line apps] | |
99 * (https://www.dartlang.org/docs/tutorials/dartio/). | |
Kathy Walrath
2013/12/16 21:18:48
I think the URL should be either dart-io or io. pr
mem
2013/12/16 22:18:55
Done.
mem
2013/12/16 22:18:55
Done.
| |
14 */ | 100 */ |
15 library dart.io; | 101 library dart.io; |
16 | 102 |
17 import 'dart:async'; | 103 import 'dart:async'; |
18 import 'dart:_collection-dev'; | 104 import 'dart:_collection-dev'; |
19 import 'dart:collection' show HashMap, | 105 import 'dart:collection' show HashMap, |
20 HashSet, | 106 HashSet, |
21 LinkedList, | 107 LinkedList, |
22 LinkedListEntry; | 108 LinkedListEntry; |
23 import 'dart:convert'; | 109 import 'dart:convert'; |
(...skipping 24 matching lines...) Expand all Loading... | |
48 part 'platform_impl.dart'; | 134 part 'platform_impl.dart'; |
49 part 'process.dart'; | 135 part 'process.dart'; |
50 part 'socket.dart'; | 136 part 'socket.dart'; |
51 part 'stdio.dart'; | 137 part 'stdio.dart'; |
52 part 'string_transformer.dart'; | 138 part 'string_transformer.dart'; |
53 part 'timer_impl.dart'; | 139 part 'timer_impl.dart'; |
54 part 'secure_socket.dart'; | 140 part 'secure_socket.dart'; |
55 part 'secure_server_socket.dart'; | 141 part 'secure_server_socket.dart'; |
56 part 'websocket.dart'; | 142 part 'websocket.dart'; |
57 part 'websocket_impl.dart'; | 143 part 'websocket_impl.dart'; |
OLD | NEW |