52 lines
1.7 KiB
Markdown
52 lines
1.7 KiB
Markdown
|
Continuing from the [previous](https://git.ablecorp.us/able/The_Programmers_ByAble/src/branch/main/Unix%3B%20Your%20mouse%20are%20a%20file.md) post we will define a very minimal example of a file and API
|
||
|
|
||
|
Here is our file definition
|
||
|
```rust
|
||
|
struct File{}
|
||
|
```
|
||
|
|
||
|
Files could have some metadata like a name
|
||
|
```rust
|
||
|
struct File{
|
||
|
@documentation["The length of the file name is limited to 100 because of simplicity"]
|
||
|
@validator[Length(100)]
|
||
|
name: String,
|
||
|
}
|
||
|
```
|
||
|
and of course the data
|
||
|
```rust
|
||
|
struct File{
|
||
|
@documentation["The length of the file name is limited to 100 because of simplicity"]
|
||
|
@validator[Length(100)]
|
||
|
name: String,
|
||
|
@documentation["Untyped raw bytes of the file"]
|
||
|
data: Vector<u8>,
|
||
|
}
|
||
|
```
|
||
|
|
||
|
|
||
|
|
||
|
Now we come to the fun part. Bikeshedding the api.
|
||
|
|
||
|
I propose a simple read/write/open/close api that supports offsets for read/write
|
||
|
```rust
|
||
|
struct File{
|
||
|
@documentation["The length of the file name is limited to 100 because of simplicity"]
|
||
|
@validator[Length(100)]
|
||
|
name: String,
|
||
|
@documentation["Untyped raw bytes of the file"]
|
||
|
data: Vector<u8>,
|
||
|
|
||
|
@documentation["The offset is to allow you do reads of specific data like the header of a file"]
|
||
|
read: function(offset: u64, length: u64) -> Vector<u8>;
|
||
|
|
||
|
@documentation["The offset is to allow you do write to specific data like the header of a file"]
|
||
|
write: function(offset: u64, data: Vector<u8>) -> None;
|
||
|
@documentation["Open a file based on a path"]
|
||
|
open: function(Path) -> File;
|
||
|
@documentation["Close a file and save all changes"]
|
||
|
close: function(None) -> None;
|
||
|
}
|
||
|
```
|
||
|
|
||
|
Small post this time that is more hand holdy. Next time will be a full filesystem definition as well as a virtual file system.
|