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

Side by Side Diff: sdk/lib/io/file_impl.dart

Issue 14611007: Don't use length when reading a file in chunks (but continue to EOF). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 part of dart.io; 5 part of dart.io;
6 6
7 // Read the file in blocks of size 64k. 7 // Read the file in blocks of size 64k.
8 const int _BLOCK_SIZE = 64 * 1024; 8 const int _BLOCK_SIZE = 64 * 1024;
9 9
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 return closeFuture; 64 return closeFuture;
65 } else { 65 } else {
66 return new Future.value(); 66 return new Future.value();
67 } 67 }
68 } 68 }
69 69
70 void _readBlock() { 70 void _readBlock() {
71 // Don't start a new read if one is already in progress. 71 // Don't start a new read if one is already in progress.
72 if (_readInProgress) return; 72 if (_readInProgress) return;
73 _readInProgress = true; 73 _readInProgress = true;
74 _openedFile.length() 74 _openedFile.read(_BLOCK_SIZE)
75 .then((length) { 75 .then((block) {
76 if (_position >= length) { 76 _readInProgress = false;
77 _readInProgress = false; 77 if (block.length == 0) {
78 if (!_unsubscribed) { 78 if (!_unsubscribed) {
79 _closeFile().then((_) { _controller.close(); }); 79 _closeFile().then((_) { _controller.close(); });
80 _unsubscribed = true; 80 _unsubscribed = true;
81 } 81 }
82 return null;
83 } else {
84 return _openedFile.read(_BLOCK_SIZE);
85 }
86 })
87 .then((block) {
88 _readInProgress = false;
89 if (block == null || _unsubscribed) {
90 return; 82 return;
91 } 83 }
92 _position += block.length; 84 _position += block.length;
93 if (_paused) { 85 if (_paused) {
94 _currentBlock = block; 86 _currentBlock = block;
95 } else { 87 } else {
96 _controller.add(block); 88 _controller.add(block);
97 _readBlock(); 89 _readBlock();
98 } 90 }
99 }) 91 })
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 new FileIOException("File closed '$_path'")); 1029 new FileIOException("File closed '$_path'"));
1038 }); 1030 });
1039 return completer.future; 1031 return completer.future;
1040 } 1032 }
1041 1033
1042 final String _path; 1034 final String _path;
1043 int _id; 1035 int _id;
1044 1036
1045 SendPort _fileService; 1037 SendPort _fileService;
1046 } 1038 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698