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

Side by Side Diff: lib/src/io.dart

Issue 1248483003: Write binstubs using the system encoding. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « lib/src/global_packages.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 /// Helper functionality to make working with IO easier. 5 /// Helper functionality to make working with IO easier.
6 library pub.io; 6 library pub.io;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:collection'; 9 import 'dart:collection';
10 import 'dart:convert'; 10 import 'dart:convert';
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 log.io("Reading binary file $file."); 158 log.io("Reading binary file $file.");
159 var contents = new File(file).readAsBytesSync(); 159 var contents = new File(file).readAsBytesSync();
160 log.io("Read ${contents.length} bytes from $file."); 160 log.io("Read ${contents.length} bytes from $file.");
161 return contents; 161 return contents;
162 } 162 }
163 163
164 /// Creates [file] and writes [contents] to it. 164 /// Creates [file] and writes [contents] to it.
165 /// 165 ///
166 /// If [dontLogContents] is true, the contents of the file will never be logged. 166 /// If [dontLogContents] is true, the contents of the file will never be logged.
167 String writeTextFile(String file, String contents, 167 String writeTextFile(String file, String contents,
168 {bool dontLogContents: false}) { 168 {bool dontLogContents: false, Encoding encoding}) {
169 if (encoding == null) encoding = UTF8;
170
169 // Sanity check: don't spew a huge file. 171 // Sanity check: don't spew a huge file.
170 log.io("Writing ${contents.length} characters to text file $file."); 172 log.io("Writing ${contents.length} characters to text file $file.");
171 if (!dontLogContents && contents.length < 1024 * 1024) { 173 if (!dontLogContents && contents.length < 1024 * 1024) {
172 log.fine("Contents:\n$contents"); 174 log.fine("Contents:\n$contents");
173 } 175 }
174 176
175 new File(file).writeAsStringSync(contents); 177 new File(file).writeAsStringSync(contents, encoding: encoding);
176 return file; 178 return file;
177 } 179 }
178 180
179 /// Creates [file] and writes [contents] to it. 181 /// Creates [file] and writes [contents] to it.
180 String writeBinaryFile(String file, List<int> contents) { 182 String writeBinaryFile(String file, List<int> contents) {
181 log.io("Writing ${contents.length} bytes to binary file $file."); 183 log.io("Writing ${contents.length} bytes to binary file $file.");
182 new File(file).openSync(mode: FileMode.WRITE) 184 new File(file).openSync(mode: FileMode.WRITE)
183 ..writeFromSync(contents) 185 ..writeFromSync(contents)
184 ..closeSync(); 186 ..closeSync();
185 log.fine("Wrote text file $file."); 187 log.fine("Wrote text file $file.");
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 1051
1050 // TODO(rnystrom): Remove this and change to returning one string. 1052 // TODO(rnystrom): Remove this and change to returning one string.
1051 static List<String> _toLines(String output) { 1053 static List<String> _toLines(String output) {
1052 var lines = splitLines(output); 1054 var lines = splitLines(output);
1053 if (!lines.isEmpty && lines.last == "") lines.removeLast(); 1055 if (!lines.isEmpty && lines.last == "") lines.removeLast();
1054 return lines; 1056 return lines;
1055 } 1057 }
1056 1058
1057 bool get success => exitCode == exit_codes.SUCCESS; 1059 bool get success => exitCode == exit_codes.SUCCESS;
1058 } 1060 }
OLDNEW
« no previous file with comments | « lib/src/global_packages.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698