OLD | NEW |
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 library vmservice_io; | 5 library vmservice_io; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 openWrites--; | 120 openWrites--; |
121 assert(openWrites >= 0); | 121 assert(openWrites >= 0); |
122 _maybeWriteFiles(); | 122 _maybeWriteFiles(); |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 Future writeFileCallback(Uri path, List<int> bytes) async { | 126 Future writeFileCallback(Uri path, List<int> bytes) async { |
127 return WriteLimiter.scheduleWrite(path, bytes); | 127 return WriteLimiter.scheduleWrite(path, bytes); |
128 } | 128 } |
129 | 129 |
| 130 Future writeStreamFileCallback(Uri path, Stream<List<int>> bytes) async { |
| 131 var file = new File.fromUri(path); |
| 132 var parent_directory = file.parent; |
| 133 await parent_directory.create(recursive: true); |
| 134 IOSink sink = await file.openWrite(); |
| 135 await sink.addStream(bytes); |
| 136 await sink.close(); |
| 137 } |
| 138 |
130 Future<List<int>> readFileCallback(Uri path) async { | 139 Future<List<int>> readFileCallback(Uri path) async { |
131 var file = new File.fromUri(path); | 140 var file = new File.fromUri(path); |
132 return await file.readAsBytes(); | 141 return await file.readAsBytes(); |
133 } | 142 } |
134 | 143 |
135 Future<List<Map<String,String>>> listFilesCallback(Uri dirPath) async { | 144 Future<List<Map<String,String>>> listFilesCallback(Uri dirPath) async { |
136 var dir = new Directory.fromUri(dirPath); | 145 var dir = new Directory.fromUri(dirPath); |
137 var dirPathStr = dirPath.path; | 146 var dirPathStr = dirPath.path; |
138 var stream = dir.list(recursive: true); | 147 var stream = dir.list(recursive: true); |
139 var result = []; | 148 var result = []; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 } | 193 } |
185 _signalSubscription = _signalWatch(ProcessSignal.SIGQUIT).listen(_onSignal); | 194 _signalSubscription = _signalWatch(ProcessSignal.SIGQUIT).listen(_onSignal); |
186 } | 195 } |
187 | 196 |
188 main() { | 197 main() { |
189 // Set embedder hooks. | 198 // Set embedder hooks. |
190 VMServiceEmbedderHooks.cleanup = cleanupCallback; | 199 VMServiceEmbedderHooks.cleanup = cleanupCallback; |
191 VMServiceEmbedderHooks.createTempDir = createTempDirCallback; | 200 VMServiceEmbedderHooks.createTempDir = createTempDirCallback; |
192 VMServiceEmbedderHooks.deleteDir = deleteDirCallback; | 201 VMServiceEmbedderHooks.deleteDir = deleteDirCallback; |
193 VMServiceEmbedderHooks.writeFile = writeFileCallback; | 202 VMServiceEmbedderHooks.writeFile = writeFileCallback; |
| 203 VMServiceEmbedderHooks.writeStreamFile = writeStreamFileCallback; |
194 VMServiceEmbedderHooks.readFile = readFileCallback; | 204 VMServiceEmbedderHooks.readFile = readFileCallback; |
195 VMServiceEmbedderHooks.listFiles = listFilesCallback; | 205 VMServiceEmbedderHooks.listFiles = listFilesCallback; |
196 // Always instantiate the vmservice object so that the exit message | 206 // Always instantiate the vmservice object so that the exit message |
197 // can be delivered and waiting loaders can be cancelled. | 207 // can be delivered and waiting loaders can be cancelled. |
198 var service = new VMService(); | 208 var service = new VMService(); |
199 if (_autoStart) { | 209 if (_autoStart) { |
200 _lazyServerBoot(); | 210 _lazyServerBoot(); |
201 server.startup(); | 211 server.startup(); |
202 // It's just here to push an event on the event loop so that we invoke the | 212 // It's just here to push an event on the event loop so that we invoke the |
203 // scheduled microtasks. | 213 // scheduled microtasks. |
204 Timer.run(() {}); | 214 Timer.run(() {}); |
205 } | 215 } |
206 scriptLoadPort.handler = _processLoadRequest; | 216 scriptLoadPort.handler = _processLoadRequest; |
207 // Register signal handler after a small delay to avoid stalling main | 217 // Register signal handler after a small delay to avoid stalling main |
208 // isolate startup. | 218 // isolate startup. |
209 _registerSignalHandlerTimer = new Timer(shortDelay, _registerSignalHandler); | 219 _registerSignalHandlerTimer = new Timer(shortDelay, _registerSignalHandler); |
210 return scriptLoadPort; | 220 return scriptLoadPort; |
211 } | 221 } |
212 | 222 |
213 _shutdown() native "VMServiceIO_Shutdown"; | 223 _shutdown() native "VMServiceIO_Shutdown"; |
OLD | NEW |