OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 import 'dart:convert'; | |
6 import 'dart:typed_data'; | |
7 | |
8 import 'package:typed_data/typed_data.dart'; | |
9 | |
10 /// A sink that provides synchronous access to the concatenated bytes passed to | |
Lasse Reichstein Nielsen
2016/04/22 09:15:13
I don't think you need to say "synchronous" here.
nweiz
2016/04/22 21:19:56
Done.
| |
11 /// it. | |
12 class ByteAccumulatorSink extends ByteConversionSinkBase { | |
13 /// The bytes accumulated so far. | |
14 /// | |
15 /// This should not be modified, although this restriction isn't enforced. | |
Lasse Reichstein Nielsen
2016/04/22 09:15:13
More precisely:
The returned `Uint8List` is viewi
nweiz
2016/04/22 21:19:56
Done.
| |
16 Uint8List get bytes => new Uint8List.view(_buffer.buffer, 0, _buffer.length); | |
17 final _buffer = new Uint8Buffer(); | |
Lasse Reichstein Nielsen
2016/04/22 09:15:13
Empty line before
nweiz
2016/04/22 21:19:56
Done.
| |
18 | |
19 /// Whether [close] has been called. | |
20 bool get isClosed => _isClosed; | |
Lasse Reichstein Nielsen
2016/04/22 09:15:13
As usual I prefer the fields before the getters. I
nweiz
2016/04/22 21:19:56
I think of fields as a special case of getters, so
| |
21 var _isClosed = false; | |
22 | |
23 void add(List<int> bytes) { | |
24 if (_isClosed) { | |
25 throw new StateError("Can't add to a closed sink."); | |
26 } | |
27 | |
28 _buffer.addAll(bytes); | |
29 } | |
30 | |
31 void addSlice(List<int> chunk, int start, int end, bool isLast) { | |
32 if (_isClosed) { | |
33 throw new StateError("Can't add to a closed sink."); | |
34 } | |
35 | |
36 _buffer.addAll(chunk, start, end); | |
37 if (isLast) _isClosed = true; | |
38 } | |
39 | |
40 void close() { | |
41 _isClosed = true; | |
42 } | |
43 } | |
OLD | NEW |