File tree Expand file tree Collapse file tree 4 files changed +40
-1
lines changed
Expand file tree Collapse file tree 4 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 1+ ## 4.2.0
2+
3+ - Add ` restorePosition ` method.
4+
15## 4.1.0
26
37- Add ` readInto ` method.
Original file line number Diff line number Diff line change @@ -59,4 +59,14 @@ abstract class RandomAccessSource {
5959
6060 /// Closes the source.
6161 Future <void > close ();
62+
63+ /// Restores the position after executing the given [action] .
64+ Future <void > restorePosition <T >(Future <T > Function () action) async {
65+ final currentPosition = await position ();
66+ try {
67+ await action ();
68+ } finally {
69+ await seek (currentPosition);
70+ }
71+ }
6272}
Original file line number Diff line number Diff line change 11name : random_access_source
22description : A shared interface for common random access data.
3- version : 4.1 .0
3+ version : 4.2 .0
44repository : https://github.com/flutter-cavalry/random_access_source
55
66environment :
Original file line number Diff line number Diff line change @@ -109,4 +109,29 @@ void main() {
109109 expect (await src.readByte (), - 1 );
110110 await src.close ();
111111 });
112+
113+ test ('RestorePosition' , () async {
114+ final src = await rafSource ();
115+ await src.seek (10 );
116+ expect (await src.position (), 10 );
117+
118+ await src.restorePosition (() async {
119+ expect (await src.position (), 10 );
120+ expect (await src.readByte (), flutterIcon[10 ]);
121+ expect (await src.position (), 11 );
122+ });
123+ expect (await src.position (), 10 );
124+
125+ try {
126+ await src.restorePosition (() async {
127+ await src.seek (20 );
128+ throw Exception ('Test Exception' );
129+ });
130+ } catch (e) {
131+ // Expected exception
132+ }
133+ expect (await src.position (), 10 );
134+
135+ await src.close ();
136+ });
112137}
You can’t perform that action at this time.
0 commit comments