@@ -100,6 +100,10 @@ pub mod rom {
100
100
/// Read the whole file with the given name from ROM.
101
101
///
102
102
/// If you have a pre-allocated buffer of the right size, use [load] instead.
103
+ ///
104
+ /// If the file does not exist, the returned buffer will be empty.
105
+ /// This, however, should not happen in normal operation because
106
+ /// the contents of the ROM directory are statically known.
103
107
#[ cfg( feature = "alloc" ) ]
104
108
#[ must_use]
105
109
pub fn load_buf ( name : & str ) -> FileBuf {
@@ -111,6 +115,12 @@ pub mod rom {
111
115
}
112
116
113
117
/// Functions for accessing files in the app data dir.
118
+ ///
119
+ /// Each app has an its own data dir. That directory is empty by default,
120
+ /// writable by the app, and not accessible by other apps.
121
+ /// Typically, it is used to store game save data.
122
+ ///
123
+ /// The device owner may empty this dir if they wish to remove the app data.
114
124
pub mod data {
115
125
use super :: * ;
116
126
use crate :: bindings as b;
@@ -146,13 +156,18 @@ pub mod data {
146
156
/// Read the whole file with the given name from the data dir.
147
157
///
148
158
/// If you have a pre-allocated buffer of the right size, use [load] instead.
159
+ ///
160
+ /// `None` is returned if the file does not exist.
149
161
#[ cfg( feature = "alloc" ) ]
150
162
#[ must_use]
151
- pub fn load_buf ( name : & str ) -> FileBuf {
163
+ pub fn load_buf ( name : & str ) -> Option < FileBuf > {
152
164
let size = data:: get_size ( name) ;
165
+ if size == 0 {
166
+ return None ;
167
+ }
153
168
let mut buf = vec ! [ 0 ; size] ;
154
169
data:: load ( name, & mut buf) ;
155
- FileBuf { raw : buf }
170
+ Some ( FileBuf { raw : buf } )
156
171
}
157
172
158
173
/// Write the buffer into the given file in the data dir.
0 commit comments