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

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

Issue 13453002: Read files in chunks, not relaying on size. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 7 /**
8 * Utility class that holds a number of byte buffers and can deliver 8 * Utility class that holds a number of byte buffers and can deliver
9 * the bytes either one by one or in chunks. 9 * the bytes either one by one or in chunks.
10 */ 10 */
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 return value; 62 return value;
63 } 63 }
64 64
65 /** 65 /**
66 * Read [count] bytes from the buffer list. If the number of bytes 66 * Read [count] bytes from the buffer list. If the number of bytes
67 * requested is not available null will be returned. 67 * requested is not available null will be returned.
68 */ 68 */
69 List<int> readBytes([int count]) { 69 List<int> readBytes([int count]) {
70 if (count == null) count = length; 70 if (count == null) count = length;
71 List<int> result; 71 List<int> result;
72 if (_length == 0 || _length < count) return null; 72 if (_length == 0) return new Uint8List(0);
73 if (_length < count) return null;
73 if (_index == 0 && _buffers.first.length == count) { 74 if (_index == 0 && _buffers.first.length == count) {
74 result = _buffers.first; 75 result = _buffers.first;
75 _buffers.removeFirst(); 76 _buffers.removeFirst();
76 _index = 0; 77 _index = 0;
77 _length -= count; 78 _length -= count;
78 return result; 79 return result;
79 } else { 80 } else {
80 int firstRemaining = _buffers.first.length - _index; 81 int firstRemaining = _buffers.first.length - _index;
81 if (firstRemaining >= count) { 82 if (firstRemaining >= count) {
82 result = _buffers.first.sublist(_index, _index + count); 83 result = _buffers.first.sublist(_index, _index + count);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 void clear() { 152 void clear() {
152 _index = 0; 153 _index = 0;
153 _length = 0; 154 _length = 0;
154 _buffers = new Queue(); 155 _buffers = new Queue();
155 } 156 }
156 157
157 int _length; // Total number of bytes remaining in the buffers. 158 int _length; // Total number of bytes remaining in the buffers.
158 Queue<List<int>> _buffers; // List of data buffers. 159 Queue<List<int>> _buffers; // List of data buffers.
159 int _index; // Index of the next byte in the first buffer. 160 int _index; // Index of the next byte in the first buffer.
160 } 161 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/io/file_impl.dart » ('j') | tests/standalone/io/file_read_special_device_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698