Skip to content
This repository was archived by the owner on Jun 3, 2020. It is now read-only.

Commit c69ef95

Browse files
committed
Merge branch 'dart_by_example-master'
Conflicts: .gitignore
2 parents 02c998a + 9c86dda commit c69ef95

File tree

62 files changed

+1428
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1428
-8
lines changed

.gitignore

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
# Dart Editor
2-
.children
3-
.project
42
*.dart.js
53
*.dart.js.map
64
*.dart.js.deps
75

86
# pub
97
packages
108

11-
# polymer
12-
.buildlog
13-
out
14-
pubspec.lock
15-
169
#other
17-
.DS_Store
1810
.settings
11+
.buildlog
12+
.DS_Store

dart_io/AUTHORS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Mary Campione
2+
Patrice Chalin
3+
Shailen Tuli
4+
Günter Zöchbauer
5+

dart_io/LICENSE

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Except as otherwise noted, the content of this page is licensed under the
2+
Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States
3+
License [1], and code samples are licensed
4+
under the BSD License:
5+
6+
Copyright 2012, the Dart project authors. All rights reserved.
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are
9+
met:
10+
* Redistributions of source code must retain the above copyright
11+
notice, this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above
13+
copyright notice, this list of conditions and the following
14+
disclaimer in the documentation and/or other materials provided
15+
with the distribution.
16+
* Neither the name of Google Inc. nor the names of its
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
32+
[1] http://creativecommons.org/licenses/by-nc-nd/3.0/us/

dart_io/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Dart By Example
2+
3+
Short snippets of code to help you become productive with Dart.
4+
5+
See the [source on Github](https://github.com/dart-lang/dart_by_example/tree/master/example).
6+
7+
Note: The Angulardart examples have been moved to
8+
[https://github.com/shailen/angulardart-samples](https://github.com/shailen/angulardart-samples).
9+
10+
## Dart I/O and command-line apps
11+
* [Introduction](example/dart_io/introduction.md)
12+
13+
### Files, directories, and symlinks
14+
* [Deleting a file, directory, or symlink](example/dart_io/files_directories_and_symlinks/deleting_a_file_directory_or_symlink.dart)
15+
* [Renaming a file, directory, or symlink](example/dart_io/files_directories_and_symlinks/renaming_a_file_directory_or_symlink.dart)
16+
* [Finding the type of a filesystem object](example/dart_io/files_directories_and_symlinks/finding_the_type_of_a_filesystem_object.dart)
17+
* [Getting the parent directory](example/dart_io/files_directories_and_symlinks/getting_the_parent_directory.dart)
18+
* [Creating a file](example/dart_io/files_directories_and_symlinks/files/creating_a_file.dart)
19+
* [Reading a file as a string](example/dart_io/files_directories_and_symlinks/files/reading_a_file_as_a_string.dart)
20+
* [Reading a file as lines](example/dart_io/files_directories_and_symlinks/files/reading_a_file_as_lines.dart)
21+
* [Reading a file as bytes](example/dart_io/files_directories_and_symlinks/files/reading_a_file_as_bytes.dart)
22+
* [Using a stream to read a file](example/dart_io/files_directories_and_symlinks/files/reading_a_file_using_a_stream.dart)
23+
* [Handling errors when reading a file](example/dart_io/files_directories_and_symlinks/files/handling_errors_when_reading_a_file.dart)
24+
* [Writing a string to a file](example/dart_io/files_directories_and_symlinks/files/writing_a_string_to_a_file.dart)
25+
* [Writing bytes to a file](example/dart_io/files_directories_and_symlinks/files/writing_bytes_to_a_file.dart)
26+
* [Using a stream to write to a file](example/dart_io/files_directories_and_symlinks/files/writing_to_a_file_using_a_stream.dart)
27+
* [Creating a directory](example/dart_io/files_directories_and_symlinks/directories/creating_a_directory.dart)
28+
* [Creating a temp directory](example/dart_io/files_directories_and_symlinks/directories/creating_a_temporary_directory.dart)
29+
* [Listing the contents of a directory](example/dart_io/files_directories_and_symlinks/directories/listing_the_contents_of_a_directory.dart)
30+
* [Creating a symlink](example/dart_io/files_directories_and_symlinks/symlinks/creating_a_symlink.dart)
31+
* [Checking if a path represents a symlink](example/dart_io/files_directories_and_symlinks/symlinks/checking_if_a_path_represents_a_symlink.dart)
32+
* [Getting the target of a symlink](example/dart_io/files_directories_and_symlinks/symlinks/getting_the_target_of_a_link.dart)
33+
34+
### HTTP requests and responses
35+
* [Making a GET request](example/dart_io/http/making_a_get_request.dart)
36+
* [Making a POST request](example/dart_io/http/making_a_post_request.dart)
37+
* [Adding custom headers to a request](example/dart_io/http/adding_custom_headers.dart)
38+
* [Making multiple requests to the same server](example/dart_io/http/making_multiple_requests_to_the_same_server.dart)
39+
* [Handling errors when making a request](example/dart_io/http/handling_an_httprequest_error.dart)
40+
* [Getting redirection history](example/dart_io/http/getting_redirection_history.dart)
41+
* [Getting the response body as a string](example/dart_io/http/reading_the_response_body.dart)
42+
* [Getting the response content in binary format](example/dart_io/http/getting_the_response_content_in_binary_format.dart)
43+
* [Getting the response headers](example/dart_io/http/getting_the_response_headers.dart)
44+
45+
### HTTP server
46+
* [Implementing a 'Hello world' HTTP server](example/dart_io/http_server/implementing_a_hello_world_http_server.dart)
47+
* [Listing directory contents](example/dart_io/http_server/listing_directory_contents.dart)
48+
* [Serving index.html](example/dart_io/http_server/serving_index_html.dart)
49+
* [Serving a 404](example/dart_io/http_server/serving_a_404.dart)
50+
* [Routing requests based on URL patterns](example/dart_io/http_server/routing_requests_based_on_url_patterns.dart)
51+
52+
### Sockets
53+
* [Using serversockets server](example/dart_io/sockets/using_serversockets_server.dart)
54+
* [Using serversockets client](example/dart_io/sockets/using_serversockets_client.dart)
55+
56+
### Websockets
57+
* [Using websockets server](example/dart_io/websockets/using_websockets_server.dart)
58+
* [Using websockets client](example/dart_io/websockets/using_websockets_client.dart)
59+
60+
### OS and hardware information
61+
* [Getting environment variables](example/dart_io/platform/getting_environment_variables.dart)
62+
* [Identifying the operating system](example/dart_io/platform/identifying_the_operating_system.dart)
63+
* [Getting information about the script being run](example/dart_io/platform/getting_information_about_the_script_being_run.dart)
64+
65+
### Interacting with processes
66+
* [Running a process](example/dart_io/interacting_with_processes/running_a_process.dart)
67+
* [Obtaining the exit code when running a process](example/dart_io/interacting_with_processes/obtaining_the_exit_code_when_running_a_process.dart)
68+
69+
### Working with paths
70+
* [Joining paths](example/dart_io/paths/joining_paths.dart)
71+
* [Parsing a path into components](example/dart_io/paths/parsing_a_path_into_components.dart)
72+
* [Calculating relative paths](example/dart_io/paths/calculating_relative_paths.dart)
73+
* [Converting between a URI and a path](example/dart_io/paths/converting_between_a_uri_and_a_path.dart)
74+
* [Getting information about a file path](example/dart_io/paths/getting_information_about_a_file_path.dart)
75+
* [Getting the path separator for the current platform](example/dart_io/paths/getting_the_path_separator_for_the_current_platform.dart)
76+
77+
### Other resources
78+
* [Other resources](example/dart_io/other_resources.md)

dart_io/example/common.css

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
body {
2+
padding-right: 15px;
3+
padding-left: 15px;
4+
margin: 20px auto 0 auto;
5+
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
6+
font-size: 14px;
7+
line-height: 1.428571429;
8+
color: #333;
9+
background-color: #fff;
10+
}
11+
12+
input[type="text"], textarea {
13+
display: block;
14+
width: 100%;
15+
height: 34px;
16+
padding: 6px 12px;
17+
font-size: 14px;
18+
line-height: 1.428571429;
19+
color: #555;
20+
vertical-align: middle;
21+
background-color: #fff;
22+
background-image: none;
23+
border: 1px solid #ccc;
24+
border-radius: 4px;
25+
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
26+
box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
27+
-webkit-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
28+
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
29+
30+
font-family: inherit;
31+
font-size: inherit;
32+
line-height: inherit;
33+
}
34+
35+
36+
input[type="checkbox"] {
37+
float: left;
38+
margin-left: -20px;
39+
margin: 3px 5px 0 0;
40+
margin-top: 1px \9;
41+
line-height: normal;
42+
padding: 0;
43+
box-sizing: border-box;
44+
}
45+
46+
47+
label {
48+
display: inline;
49+
margin-bottom: 0;
50+
font-weight: normal;
51+
cursor: pointer;
52+
}
53+
54+
select {
55+
display: block;
56+
width: 100%;
57+
height: 34px;
58+
padding: 6px 12px;
59+
font-size: 14px;
60+
line-height: 1.428571429;
61+
color: #555;
62+
vertical-align: middle;
63+
background-color: #fff;
64+
background-image: none;
65+
border: 1px solid #ccc;
66+
border-radius: 4px;
67+
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
68+
box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
69+
-webkit-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
70+
transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
71+
}
72+
73+
button, input[type='submit'] {
74+
display: inline-block;
75+
padding: 6px 12px;
76+
margin-top: 10px;
77+
margin-bottom: 0;
78+
font-size: 14px;
79+
font-weight: normal;
80+
line-height: 1.428571429;
81+
text-align: center;
82+
white-space: nowrap;
83+
vertical-align: middle;
84+
cursor: pointer;
85+
background-image: none;
86+
border: 1px solid transparent;
87+
border-radius: 4px;
88+
-webkit-user-select: none;
89+
-moz-user-select: none;
90+
-ms-user-select: none;
91+
-o-user-select: none;
92+
user-select: none;
93+
color: #fff;
94+
background-color: #428bca;
95+
border-color: #357ebd;
96+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// Use the FilesSystemEntity `delete()` method to delete a file, directory, or
6+
/// symlink. This method is inherited by File, Directory, and Link.
7+
8+
9+
import 'dart:io';
10+
11+
void main() {
12+
// Create a temporary directory.
13+
Directory.systemTemp.createTemp('my_temp_dir')
14+
.then((directory) {
15+
// Confirm it exists.
16+
directory.exists().then(print); // Prints 'true'.
17+
// Delete the directory.
18+
return directory.delete();
19+
})
20+
.then((directory) {
21+
// Confirm it no longer exists.
22+
directory.exists().then(print); // Prints 'false'
23+
});
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// Use the Directory `create()` method to create a directory.
6+
/// To create intermediate directories, set the `recursive` argument to `true`
7+
/// (default is `false`).
8+
9+
import 'dart:io';
10+
11+
void main() {
12+
// Creates dir/ and dir/subdir/.
13+
new Directory('dir/subdir').create(recursive: true)
14+
// The created directory is returned as a Future.
15+
.then((Directory directory) {
16+
print(directory.path);
17+
});
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// Use the Directory `createTemp()` method to create a temporary directory.
6+
/// This method appends random characters to the name of the directory to
7+
/// produce a unique directory name.
8+
9+
import 'dart:io';
10+
11+
void main() {
12+
// Create a temporary directory in the system temp directory.
13+
Directory.systemTemp.createTemp('my_temp_dir')
14+
.then((directory) {
15+
print(directory.path);
16+
});
17+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// Use the `list()` method to list a directory's contents. The method recurses
6+
/// into subdirectories if the `recursive` argument is `true` (default is
7+
/// `false`). It does not follow symlinks if the `followLinks` argument is
8+
/// `false` (default is `true`).
9+
10+
import 'dart:io';
11+
12+
void main() {
13+
// Get the system temp directory.
14+
var systemTempDir = Directory.systemTemp;
15+
16+
// List directory contents, recursing into sub-directories, but not following
17+
// symbolic links.
18+
systemTempDir.list(recursive: true, followLinks: false)
19+
.listen((FileSystemEntity entity) {
20+
print(entity.path);
21+
});
22+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
one banana
2+
two banana
3+
three banana
4+
four

0 commit comments

Comments
 (0)