From fda94904b17f1283506252c9933601871525eacc Mon Sep 17 00:00:00 2001 From: Mgen Date: Tue, 26 Nov 2024 12:26:57 +0800 Subject: [PATCH] v2.0 --- CHANGELOG.md | 5 +++ README.md | 6 ++-- pubspec.yaml | 2 +- test/bytes_sync_test.dart | 72 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 test/bytes_sync_test.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 9af38f2..8908e08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.0 + +- **BREAKING** Rename `RandomAccessFileRASource` to `FileRASource`. +- Add `SyncBytesRASource`. + ## 1.2.0 - Add `readToEnd`. diff --git a/README.md b/README.md index 0076b73..b051d16 100644 --- a/README.md +++ b/README.md @@ -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 @@ -34,5 +34,5 @@ abstract class RandomAccessSource { Implementations: -- `BytesRASource` for `Uint8List` data -- `FileRASource` for `RandomAccessFile` data +- `BytesRASource` for `Uint8List`. +- `FileRASource` for `RandomAccessFile`. diff --git a/pubspec.yaml b/pubspec.yaml index 2aae954..e361258 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/bytes_sync_test.dart b/test/bytes_sync_test.dart new file mode 100644 index 0000000..200f366 --- /dev/null +++ b/test/bytes_sync_test.dart @@ -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); + }); +}