Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6c1375b

Browse files
committedJun 10, 2025·
Add mustRead
1 parent 25816ca commit 6c1375b

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed
 

‎CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.2.1
2+
3+
- Add `mustRead`.
4+
15
## 2.2.0
26

37
- Remove undocumented binary reader.

‎lib/src/random_access_source.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,14 @@ abstract class RandomAccessSource {
2222

2323
/// Closes the source.
2424
Future<void> close();
25+
26+
/// Reads a specific number of bytes, ensuring that the exact number is read.
27+
/// Throws an exception if the number of bytes read is not equal to [length].
28+
Future<Uint8List> mustRead(int length) async {
29+
final bytes = await read(length);
30+
if (bytes.length != length) {
31+
throw Exception('Failed to read $length bytes, got ${bytes.length}');
32+
}
33+
return bytes;
34+
}
2535
}

‎pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: random_access_source
22
description: A shared interface for common random access data.
3-
version: 2.2.0
3+
version: 2.2.1
44
repository: https://github.com/flutter-cavalry/random_access_source
55

66
environment:

0 commit comments

Comments
 (0)
Please sign in to comment.