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

Unified Diff: samples/chat/chat_server_lib.dart

Issue 8883017: Split File into File and RandomAccessFile. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 9 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/file_impl.dart ('k') | tests/standalone/src/DirectoryTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/chat/chat_server_lib.dart
diff --git a/samples/chat/chat_server_lib.dart b/samples/chat/chat_server_lib.dart
index 51b36dc208918e57860fa4c6c52fc444cd3d3bd2..883214c3104521337ddb48028c94e222f7fa7eca 100644
--- a/samples/chat/chat_server_lib.dart
+++ b/samples/chat/chat_server_lib.dart
@@ -366,7 +366,7 @@ class IsolatedServer extends Isolate {
}
File file = new File(fileName);
if (file.existsSync()) {
- file.openSync();
+ RandomAccessFile openedFile = file.openSync();
int totalRead = 0;
List<int> buffer = new List<int>(BUFFER_SIZE);
@@ -380,21 +380,32 @@ class IsolatedServer extends Isolate {
if (extension == ".png") { mimeType = "image/png"; }
}
response.setHeader("Content-Type", mimeType);
- response.contentLength = file.lengthSync();
+ response.contentLength = openedFile.lengthSync();
+
+ bool checkDone() {
+ if (totalRead == openedFile.lengthSync()) {
+ openedFile.closeSync();
+ response.writeDone();
+ return true;
+ }
+ return false;
+ }
void writeFileData() {
- while (totalRead < file.lengthSync()) {
- var read = file.readListSync(buffer, 0, BUFFER_SIZE);
+ if (checkDone()) return;
+ while (totalRead < openedFile.lengthSync()) {
+ var read = openedFile.readListSync(buffer, 0, BUFFER_SIZE);
totalRead += read;
// Write this buffer and get a callback when it makes sense
// to write more.
- bool allWritten = response.writeList(buffer, 0, read, writeFileData);
- if (!allWritten) break;
- }
-
- if (totalRead == file.lengthSync()) {
- response.writeDone();
+ bool writeCompleted =
+ response.writeList(buffer, 0, read, writeFileData);
+ if (writeCompleted) {
+ if (checkDone()) return;
+ } else {
+ break;
+ }
}
}
« no previous file with comments | « runtime/bin/file_impl.dart ('k') | tests/standalone/src/DirectoryTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698