OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'package:analyzer/file_system/file_system.dart'; | 5 import 'package:analyzer/file_system/file_system.dart'; |
6 import 'package:analyzer/src/dart/analysis/byte_store.dart'; | 6 import 'package:analyzer/src/dart/analysis/byte_store.dart'; |
7 | 7 |
8 /** | 8 /** |
9 * [ByteStore] that stores values as [File]s. | 9 * [ByteStore] that stores values as [File]s. |
| 10 * |
| 11 * TODO(scheglov) Add some eviction policies. |
10 */ | 12 */ |
11 class FileByteStore implements ByteStore { | 13 class FileByteStore implements ByteStore { |
12 final Folder folder; | 14 final Folder folder; |
13 | 15 |
14 FileByteStore(this.folder); | 16 FileByteStore(this.folder); |
15 | 17 |
16 @override | 18 @override |
17 List<int> get(String key) { | 19 List<int> get(String key) { |
18 try { | 20 try { |
19 File file = folder.getChildAssumingFile(key); | 21 File file = folder.getChildAssumingFile(key); |
20 return file.readAsBytesSync(); | 22 return file.readAsBytesSync(); |
21 } catch (_) { | 23 } catch (_) { |
22 return null; | 24 return null; |
23 } | 25 } |
24 } | 26 } |
25 | 27 |
26 @override | 28 @override |
27 void put(String key, List<int> bytes) { | 29 void put(String key, List<int> bytes) { |
28 try { | 30 try { |
29 File file = folder.getChildAssumingFile(key); | 31 File file = folder.getChildAssumingFile(key); |
30 file.writeAsBytesSync(bytes); | 32 file.writeAsBytesSync(bytes); |
31 } catch (_) {} | 33 } catch (_) {} |
32 } | 34 } |
33 } | 35 } |
OLD | NEW |