44/// Firefly Zero runtime enforces flat structure for app data and ROMs,
55/// so the path cannot contain path separators (`/`).
66///
7+ /// Must be UTF-8 encoded.
78/// Any String literal or Bytes literal is a valid ASCII string:
89///
910/// ```text
1011/// @firefly.load_file("font")
1112/// ```
1213pub type Path = Bytes
1314
15+ ///|
16+ pub type PathView = BytesView
17+
1418///|
1519/// Get size (in bytes) of a file from ROM or the data directory.
1620///
1721/// Returns 0 if the file does not exist.
18- pub fn get_file_size (path : Path ) -> Int {
22+ pub fn get_file_size (path : PathView ) -> Int {
1923 let size = @ffi .get_file_size (
20- @memory .bytes_addr (path ),
21- @memory .bytes_size (path ),
24+ @memory .bytesview_addr (path ),
25+ @memory .bytesview_size (path ),
2226 )
2327 @memory .keep (path )
2428 size
@@ -27,24 +31,24 @@ pub fn get_file_size(path : Path) -> Int {
2731///|
2832/// Check if the given path points to a file in ROM or the data directory.
2933#inline
30- pub fn is_file (path : Path ) -> Bool {
34+ pub fn is_file (path : PathView ) -> Bool {
3135 get_file_size (path ) != 0
3236}
3337
3438///|
3539/// Load a file from ROM or the data directory.
3640///
3741/// Example: loading fonts, images, or save files.
38- pub fn load_file (path : Path ) -> File? {
42+ pub fn load_file (path : PathView ) -> File? {
3943 let size = @ffi .get_file_size (
40- @memory .bytes_addr (path ),
41- @memory .bytes_size (path ),
44+ @memory .bytesview_addr (path ),
45+ @memory .bytesview_size (path ),
4246 )
4347 guard size != 0 else { None }
4448 let buf = FixedArray ::make (size , Byte ::default ())
4549 let _ = @ffi .load_file (
46- @memory .bytes_addr (path ),
47- @memory .bytes_size (path ),
50+ @memory .bytesview_addr (path ),
51+ @memory .bytesview_size (path ),
4852 @memory .fixedbytes_addr (buf ),
4953 @memory .fixedbytes_size (buf ),
5054 )
@@ -58,10 +62,10 @@ pub fn load_file(path : Path) -> File? {
5862/// Returns the number of bytes that has been loaded.
5963///
6064/// Example: loading fonts, images, or save files.
61- pub fn load_file_to (path : Path , output : FixedArray [Byte ]) -> Int {
65+ pub fn load_file_to (path : PathView , output : FixedArray [Byte ]) -> Int {
6266 let size = @ffi .load_file (
63- @memory .bytes_addr (path ),
64- @memory .bytes_size (path ),
67+ @memory .bytesview_addr (path ),
68+ @memory .bytesview_size (path ),
6569 @memory .fixedbytes_addr (output ),
6670 @memory .fixedbytes_size (output ),
6771 )
@@ -78,10 +82,10 @@ pub fn load_file_to(path : Path, output : FixedArray[Byte]) -> Int {
7882/// Example: writing save files.
7983///
8084/// Returns the number of bytes written.
81- pub fn dump_file (path : Path , file : File ) -> Int {
85+ pub fn dump_file (path : PathView , file : File ) -> Int {
8286 let size = @ffi .load_file (
83- @memory .bytes_addr (path ),
84- @memory .bytes_size (path ),
87+ @memory .bytesview_addr (path ),
88+ @memory .bytesview_size (path ),
8589 @memory .fixedbytes_addr (file .0 ),
8690 @memory .fixedbytes_size (file .0 ),
8791 )
@@ -93,7 +97,7 @@ pub fn dump_file(path : Path, file : File) -> Int {
9397/// Removes a file (if exists) from the data directory.
9498///
9599/// Example: removing save files.
96- pub fn remove_file (path : Path ) -> Unit {
97- @ffi .remove_file (@memory .bytes_addr (path ), @memory .bytes_size (path ))
100+ pub fn remove_file (path : PathView ) -> Unit {
101+ @ffi .remove_file (@memory .bytesview_addr (path ), @memory .bytesview_size (path ))
98102 @memory .keep (path )
99103}
0 commit comments