Skip to content

Commit

Permalink
v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mgenware committed Nov 26, 2024
1 parent 0dbc3a7 commit fda9490
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.0

- **BREAKING** Rename `RandomAccessFileRASource` to `FileRASource`.
- Add `SyncBytesRASource`.

## 1.2.0

- Add `readToEnd`.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![pub package](https://img.shields.io/pub/v/random_access_source.svg)](https://pub.dev/packages/random_access_source)
[![Build Status](https://github.com/flutter-cavalry/random_access_source/workflows/Dart/badge.svg)](https://github.com/flutter-cavalry/random_access_source/actions)

Shared interfaces for random access data
A shared interface for common random access data.

## Usage

Expand Down Expand Up @@ -34,5 +34,5 @@ abstract class RandomAccessSource {

Implementations:

- `BytesRASource` for `Uint8List` data
- `FileRASource` for `RandomAccessFile` data
- `BytesRASource` for `Uint8List`.
- `FileRASource` for `RandomAccessFile`.
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: random_access_source
description: Shared interfaces for random access data.
description: A shared interface for common random access data.
version: 1.2.0
repository: https://github.com/flutter-cavalry/random_access_source

Expand Down
72 changes: 72 additions & 0 deletions test/bytes_sync_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import 'dart:typed_data';

import 'package:random_access_source/random_access_source.dart';
import 'package:test/test.dart';

SyncBytesRASource _bytesSource() {
return SyncBytesRASource(Uint8List.fromList([1, 2, 3, 4, 5]));
}

void main() {
test('Length', () async {
final src = _bytesSource();
expect(src.length(), 5);
});

test('ReadByte', () async {
final src = _bytesSource();
expect(src.readByte(), 1);
expect(src.position(), 1);

expect(src.readByte(), 2);
expect(src.position(), 2);

expect(src.readByte(), 3);
expect(src.position(), 3);

expect(src.readByte(), 4);
expect(src.position(), 4);

expect(src.readByte(), 5);
expect(src.position(), 5);

expect(src.readByte(), -1);
expect(src.position(), 5);
});

test('Read', () async {
final src = _bytesSource();
expect(src.read(2), Uint8List.fromList([1, 2]));
expect(src.position(), 2);

expect(src.read(2), Uint8List.fromList([3, 4]));
expect(src.position(), 4);

expect(src.read(2), Uint8List.fromList([5]));
expect(src.position(), 5);

expect(src.read(2), Uint8List(0));
expect(src.position(), 5);
});

test('Position', () async {
final src = _bytesSource();
expect(src.position(), 0);
src.setPosition(2);
expect(src.position(), 2);
expect(src.readByte(), 3);
});

test('ReadToEnd', () async {
final src = _bytesSource();
expect(src.readToEnd(), Uint8List.fromList([1, 2, 3, 4, 5]));
expect(src.position(), 5);
});

test('ReadToEnd (halfway)', () async {
final src = _bytesSource();
src.setPosition(2);
expect(src.readToEnd(), Uint8List.fromList([3, 4, 5]));
expect(src.position(), 5);
});
}

0 comments on commit fda9490

Please sign in to comment.