OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 library fasta.scanner.io; | 5 library fasta.scanner.io; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show Future; |
8 Future; | |
9 | 8 |
10 import 'dart:io' show | 9 import 'dart:io' show File, RandomAccessFile; |
11 File, | |
12 RandomAccessFile; | |
13 | 10 |
14 import 'dart:typed_data' show | 11 import 'dart:typed_data' show Uint8List; |
15 Uint8List; | |
16 | 12 |
17 List<int> readBytesFromFileSync(Uri uri) { | 13 List<int> readBytesFromFileSync(Uri uri) { |
18 RandomAccessFile file = new File.fromUri(uri).openSync(); | 14 RandomAccessFile file = new File.fromUri(uri).openSync(); |
19 Uint8List list; | 15 Uint8List list; |
20 try { | 16 try { |
21 int length = file.lengthSync(); | 17 int length = file.lengthSync(); |
22 // +1 to have a 0 terminated list, see [Scanner]. | 18 // +1 to have a 0 terminated list, see [Scanner]. |
23 list = new Uint8List(length + 1); | 19 list = new Uint8List(length + 1); |
24 file.readIntoSync(list, 0, length); | 20 file.readIntoSync(list, 0, length); |
25 } finally { | 21 } finally { |
(...skipping 11 matching lines...) Expand all Loading... |
37 list = new Uint8List(length + 1); | 33 list = new Uint8List(length + 1); |
38 int read = await file.readInto(list); | 34 int read = await file.readInto(list); |
39 if (read != length) { | 35 if (read != length) { |
40 throw "Error reading file: ${uri}"; | 36 throw "Error reading file: ${uri}"; |
41 } | 37 } |
42 } finally { | 38 } finally { |
43 await file.close(); | 39 await file.close(); |
44 } | 40 } |
45 return list; | 41 return list; |
46 } | 42 } |
OLD | NEW |