Skip to content

Commit fda9490

Browse files
committed
v2.0
1 parent 0dbc3a7 commit fda9490

File tree

4 files changed

+81
-4
lines changed

4 files changed

+81
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.0.0
2+
3+
- **BREAKING** Rename `RandomAccessFileRASource` to `FileRASource`.
4+
- Add `SyncBytesRASource`.
5+
16
## 1.2.0
27

38
- Add `readToEnd`.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![pub package](https://img.shields.io/pub/v/random_access_source.svg)](https://pub.dev/packages/random_access_source)
44
[![Build Status](https://github.com/flutter-cavalry/random_access_source/workflows/Dart/badge.svg)](https://github.com/flutter-cavalry/random_access_source/actions)
55

6-
Shared interfaces for random access data
6+
A shared interface for common random access data.
77

88
## Usage
99

@@ -34,5 +34,5 @@ abstract class RandomAccessSource {
3434

3535
Implementations:
3636

37-
- `BytesRASource` for `Uint8List` data
38-
- `FileRASource` for `RandomAccessFile` data
37+
- `BytesRASource` for `Uint8List`.
38+
- `FileRASource` for `RandomAccessFile`.

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: random_access_source
2-
description: Shared interfaces for random access data.
2+
description: A shared interface for common random access data.
33
version: 1.2.0
44
repository: https://github.com/flutter-cavalry/random_access_source
55

test/bytes_sync_test.dart

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import 'dart:typed_data';
2+
3+
import 'package:random_access_source/random_access_source.dart';
4+
import 'package:test/test.dart';
5+
6+
SyncBytesRASource _bytesSource() {
7+
return SyncBytesRASource(Uint8List.fromList([1, 2, 3, 4, 5]));
8+
}
9+
10+
void main() {
11+
test('Length', () async {
12+
final src = _bytesSource();
13+
expect(src.length(), 5);
14+
});
15+
16+
test('ReadByte', () async {
17+
final src = _bytesSource();
18+
expect(src.readByte(), 1);
19+
expect(src.position(), 1);
20+
21+
expect(src.readByte(), 2);
22+
expect(src.position(), 2);
23+
24+
expect(src.readByte(), 3);
25+
expect(src.position(), 3);
26+
27+
expect(src.readByte(), 4);
28+
expect(src.position(), 4);
29+
30+
expect(src.readByte(), 5);
31+
expect(src.position(), 5);
32+
33+
expect(src.readByte(), -1);
34+
expect(src.position(), 5);
35+
});
36+
37+
test('Read', () async {
38+
final src = _bytesSource();
39+
expect(src.read(2), Uint8List.fromList([1, 2]));
40+
expect(src.position(), 2);
41+
42+
expect(src.read(2), Uint8List.fromList([3, 4]));
43+
expect(src.position(), 4);
44+
45+
expect(src.read(2), Uint8List.fromList([5]));
46+
expect(src.position(), 5);
47+
48+
expect(src.read(2), Uint8List(0));
49+
expect(src.position(), 5);
50+
});
51+
52+
test('Position', () async {
53+
final src = _bytesSource();
54+
expect(src.position(), 0);
55+
src.setPosition(2);
56+
expect(src.position(), 2);
57+
expect(src.readByte(), 3);
58+
});
59+
60+
test('ReadToEnd', () async {
61+
final src = _bytesSource();
62+
expect(src.readToEnd(), Uint8List.fromList([1, 2, 3, 4, 5]));
63+
expect(src.position(), 5);
64+
});
65+
66+
test('ReadToEnd (halfway)', () async {
67+
final src = _bytesSource();
68+
src.setPosition(2);
69+
expect(src.readToEnd(), Uint8List.fromList([3, 4, 5]));
70+
expect(src.position(), 5);
71+
});
72+
}

0 commit comments

Comments
 (0)