the new post :)
This commit is contained in:
parent
b4543c81ec
commit
bd1107f412
52
Files; an overview.md
Normal file
52
Files; an overview.md
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
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.
|
|
@ -1,4 +1,4 @@
|
||||||
A file is a wonderful abstraction over raw data on a storage device.
|
A [file](https://git.ablecorp.us/able/The_Programmers_ByAble/src/branch/main/Files%3B%20an%20overview.md) is a wonderful abstraction over raw data on a storage device.
|
||||||
Users don't want to think about how many blocks on a disk their data takes up.
|
Users don't want to think about how many blocks on a disk their data takes up.
|
||||||
They want a nice clean efficient way to reference all of the data, as such filesystems were a genius idea.
|
They want a nice clean efficient way to reference all of the data, as such filesystems were a genius idea.
|
||||||
A mouse device by design has some state which can be represented in a certian way, say we use JSON.
|
A mouse device by design has some state which can be represented in a certian way, say we use JSON.
|
||||||
|
|
Loading…
Reference in a new issue